LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   g++ compiler help (https://www.linuxquestions.org/questions/programming-9/g-compiler-help-35767/)

bigpimpin79 11-18-2002 09:45 AM

g++ compiler help
 
hello
i am a first time linux user and had just installed RH Linux 8 on my PC. i seem to have a problem using the g++ compiler.

my code is:

#include<iostream>
int main(){
cout<<"Hello World";
return 0;
}

the compiler error that i get is:

Hello.cc:3:'cout' undeclared(first use this function)
Hello.cc:3:each undeclared identifier is reported only once for each function it appears in.)

help, anyone?
thanks!

acid_kewpie 11-18-2002 09:50 AM

you are not using cout in teh correct namespace. either say:
Code:

using namespace std;
or
Code:

std::cout<<"Hello World";
that'll compile it, but it still won't work, as you're not flushing the output stream, you'll want something like:
Code:

cout<<"Hello World" << endl;
instead

bigpimpin79 11-18-2002 05:42 PM

thanks!

how come you have add that extra piece of code just to make iostream work? i have been writing and compiling in RH Linux 7.3 and the '#include<iostream>' alone worked fine.

thanks again

acid_kewpie 11-18-2002 05:45 PM

i don't know, if it was working before, it was wrong somewhere alogn the line.

Tinkster 11-18-2002 07:23 PM

Quote:

Originally posted by bigpimpin79
thanks!

how come you have add that extra piece of code just to make iostream work? i have been writing and compiling in RH Linux 7.3 and the '#include<iostream>' alone worked fine.

thanks again

That's because the standard that requires
'std::' or the usage of 'using namespace std;'
(which, btw, isn't encouraged) is only about
4 years old :} and some compiler-builders
are slow to respond ;)
Cheers,
Tink


All times are GMT -5. The time now is 10:32 AM.