I do not want to discuss about C++ or any programming language!I just want to know what am i doing wrong with linux ubuntu about compiling helloworld.cpp!
I am learning C++ so my steps are:
open hello.cpp in vim and write this
#include <iostream.h>
int main()
{
cout << "Hello World!\n";`
return 0;
}
So, after that i tried in the terminal this
g++ hello.cpp
AND the output is
hello.cpp:1:22: fatal error: iostream.h: No such file or directory
compilation terminated.
What do you suggest? Any useful step by step guide for me?Thanks!
You should use
#include <iostream>
, notiostream.h
; the .h form is very old and deprecated since years.You can read more than you probably want to know on the .h vs non-.h forms here: http://members.gamedev.net/sicrane/articles/iostream.html
(Plus, you should write
std::cout
or have a lineusing namespace std;
otherwise your next error will be about the compiler not finding a definition forcout
.)You should change
iostream.h
toiostream
. I was also getting the same error as you are getting, but when I changediostream.h
to justiostream
, it worked properly. Maybe it would work for you as well.In other words, change the line that says:
Make it say this instead:
The C++ standard library header files, as defined in the standard, do not have
.h
extensions.As mentioned Riccardo Murri's answer, you will also need to call
cout
by its fully qualified namestd::cout
, or have one of these two lines (preferably below your#include
directives but above your other code):The second way is considered preferable, especially for serious programming projects, since it only affects
std::cout
, rather than bringing in all the names in thestd
namespace (some of which might potentially interfere with names used in your program).