ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi, i'm having a little problem with gcc and headers. I'm trying to learn C++ and when I try to compile a simple hello world with gcc, it yells at me for using iostream.h but when I #include<iostream>, it (i assume, because it says first use of cout when compiling) can't find it. I don't know where header files are kept on a linux system or even how i would go about updating gcc because i probably should considering that this is the one on the original cds from redhat 9. Thanks in advance.
here is the program. . . can't get much more simple than this:
Code:
#include<iostream>
int main ()
{
cout << "Hello, World!" <<endl;
return 0;
}
here is the return from the console when i try to compile it:
Code:
g++ hello.C -o hello
hello.C: In function `int main()':
hello.C:5: `cout' undeclared (first use this function)
hello.C:5: (Each undeclared identifier is reported only once for each function
it appears in.)
hello.C:5: `endl' undeclared (first use this function)
hello.C:8:2: warning: no newline at end of file
Is there any difference between g++ and gcc. btw? Each way gave me the same error output.
g++ hello.C -o hello
In file included from /usr/include/c++/3.2.2/backward/iostream.h:31,
from hello.C:1:
/usr/include/c++/3.2.2/backward/backward_warning.h:32:2: warning: #warning This
file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples
include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning
use -Wno-deprecated.
Originally posted by aditya1 try this i twill surely help you
#include<iostream>
using namespace std;
int main()
{//write your program
}
Wow, that worked. No errors now. That is very good because I'm using RedHat9 and updating gcc would have required me to also upgrade so much other stuff that I was going to do an entire OS upgrade. I didn't really feel like doing that.
Actually, is RH9 now so old that I should do an OS upgrade anyway?
As you noticed, the reason that <iostream> didn't work for you, but <iostream.h> did is because <iostream> puts everything into the std namespace. Adding the line "using namespace std;" is one way to cause it to inject everything in the std namespace into the global namespace.
Alternatively, you could have used std::cout and std::endl, to explicitly specify the namespace that they are in.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.