For names that are brought in by standard includes like cout
, there are 3 things that may be done:
Prefix the NAME with std::
.
Use using std::NAME
before the name is used.
Put using namespace::std
before the name is used.
Do NOT use option 3. You may see it used, even in text books, but it is bad programming practice.
These examples use cout
for NAME:
Prefix the NAME with std::
int main()
{
std::cout >> "Hello World!\n";
// ...
Use using std::NAME
before the name is used
// File scope, avoid this one
//using std::cout;
int main()
{
// Block scope
using std::cout;
cout >> "Hello World!\n";
// ...
Put using namespace::std before the name is used.
// Do not use this
using namespace std;
int main()
{
cout >> "Hello World!\n";
// ...