The
std namespace is required, when using
cin,
cout and
endl among others.
When you declare, that you are using a specific namespace, then you maek sure, that your code will use the implementations of those functions as declared in the std namespace.
If you were to combine your code with code from others, then you might end up with an unexpected error, if you're not addressing the namespace required for your part of the code.
An example:
Code:
// the code from others
using err::cout;
using std::cin;
using std:: endl;
int error_function(string error)
{
cout << error.c_str() << endl;
return 0;
}
// your code
int my_function(string some_string, string *other_string)
{
if(some_condition)
{
cout << some_string.c_str() << endl;
other_string = "No user input";
}
else
cin.getline(other_string, '\n');
return 0;
}
If you're not declaring, that you're using
std namespace you will be using the err namespace of cout, which could be whatever the previus coder declared that as, beeing writing to stderr, stdout, a file or whatever.
Now if you in your code, specificaly tells it to be using
std namespace you're sure that what ever you parse to cout, will allways end up where the std namespace redirects it, usualy stdout.