LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   g++ compiler cannot locate its library in my fedora machine (https://www.linuxquestions.org/questions/linux-newbie-8/g-compiler-cannot-locate-its-library-in-my-fedora-machine-625071/)

khandielas 03-02-2008 01:19 AM

g++ compiler cannot locate its library in my fedora machine
 
Hi, all, new to LINUX. cannot successfully compile.
I run fedora 7, gcc version
[root@ Basics]# gcc --version
gcc (GCC) 4.1.2 20070925 (Red Hat 4.1.2-27)

I can find gcc library under /usr/include/c++/4.1.2/iostream

#include <iosteam>
int main()
{
cout << "hello, world" << endl;
return 0;
}

I got this when compuling:
[root@ Basics]# g++ hello.cpp
hello.cpp: In function ‘int main()’:
hello.cpp:5: error: ‘cout’ was not declared in this scope
hello.cpp:5: error: ‘endl’ was not declared in this scope

a piece of test code:
int main() { return 0 }
#g++ test.cpp
It does not show any error.

Nylex 03-02-2008 07:51 AM

You need to either add a "using namespace std;" line below your include directive, or change "cout" and "endl" to "std::cout" and "std::endl" respectively.

Also, you're not using the root account all the time are you? If so, you really should make a regular user account for everyday use.

khandielas 03-02-2008 11:46 AM

Quote:

Originally Posted by Nylex (Post 3075598)
You need to either add a "using namespace std;" line below your include directive, or change "cout" and "endl" to "std::cout" and "std::endl" respectively.

Also, you're not using the root account all the time are you? If so, you really should make a regular user account for everyday use.

Thank you very much. It works fine with std namespace. Thought compiler always choose std as default -:). I also created user acct, thanks for the reminder!


All times are GMT -5. The time now is 06:47 PM.