You must include it in order to read or write to the standard input/output streams.
int main( int argc, char * argv[] )
{
std::cout << "Hello World!" << std::endl;
return 0;
}
Unless you include #include iostream>, that programme will not build.
The second line isn't required.
using namespace std;
That tells the compiler that symbol names declared in the std namespace should be brought into the scope of your programme, so you may skip the namespace qualifier and write for example.
#include <iostream>
using namespace std;
int main( int argc, char * argv[] )
{
cout << "Hello World!" << endl;
return 0;
}
Notice you no longer need to refer to the output stream with the fully qualified name std::cout and can use the shorter name cout.
I personally don't like bringing in all symbols in the namespace of a header file... I'll individually select the symbols I want to be shorter... so I would do this:
#include <iostream>
using std::cout;
using std::endl;
int main( int argc, char * argv[] )
{
cout << "Hello World!" << endl;
return 0;
}
However, this is a question of personal choice.