Suse & OpenSuse : Tips, Tricks, Tutorials, How Tos and Troubleshooting

Compiling C++ code using iostream in G++ version 4.3 and above

In the past, prior to G++ version 4.3, a code like

#include <iostream.h>
int main() {
  cout << “hello world” << endl;
  return 0;
}

would probably compile  (g++ <filename.cpp>) with the possibility of some warning messages.  With version 4.3 and newer, it will give you an error message stating that

iostream.h: No such file or directory

There are mainly 2 changes here; (1) GCC 4.3 does not recognize iostream.h anymore and will comply with the latest C++ standards of using iostream and (2) you will need to have “using namespace std;” at the top for it to recognize iostream.

using namespace std;

#include <iostream>
int main() {
  cout << “hello world” << endl;
  return 0;
}

And compile it with g++.

This is only IF you have not been following proper C++ standards and especially so, when you mix C and C++ code together.  If you did learned to code C++ properly, you would not have such an issue anyway.

RSS feed | Trackback URI

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.