View Single Post
Old 05-04-2005, 01:41 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
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.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote