In order to read or write the standard input or output streams, you need to include it by using:-
int main( int argc, char * argv[] )
{
std::cout << "Hello World!" << std::endl;
return 0;
}
This given program will not compile unless you add #include <iostream> and also the second line is not needed:-
using namespace std;
This function will inform the compiler that the name symbol which is defined in the std namespace has to be brought in the scope of the program to let you remove the qualifier of the namespace. Below is an example:-
#include <iostream>
using namespace std;
int main( int argc, char * argv[] )
{
cout << "Hello World!" << endl;
return 0;
}
You would have noticed that there is no longer a need to refer to the output stream with the entire qualified name std::cout and one can use the shorter name cout. I would personally recommend not to bring in all symbols in the namespace of a header file and rather you should individually select the symbols which you would want to be shorter so I would suggest you use this:
#include <iostream>
using std::cout;
using std::endl;
int main( int argc, char * argv[] )
{
cout << "Hello World!" << endl;
return 0;
}
Please note that this is subjective and a matter of personal preference.