What's the point of doing "using std::cout;"?

I see examples with "using cout"? What's the point of this if you have to type it out on the code anyways? For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>

using std::cout;
using std::cin;
using std::endl;
using std::ios;

#include <iomanip>

using std::setprecision;
using std::setiosflags;

int main()
{
    int total,gradeCounter,grade;
    double average;

// initialization phase
    total = 0;
    gradeCounter = 0;

// processing phase
    cout << "Enter grade,-1 to end: ";
    cin >> grade;

    while ( grade != -1 ) {
        total = total + grade;
        gradeCounter = gradeCounter + 1;
        cout << "Enter grade,-1 to end: ";
        cin >> grade;
}
    if ( gradeCounter != 0 ) {
        average = static_cast < double > (total) / gradeCounter;
        cout << "Class average is " << setprecision( 2 )
            << setiosflags ( ios::fixed | ios::showpoint )
            << average << endl;
}
    else
        cout << "No grade were entered" << endl;

return 0;
}


I was to lazy so I printed the whole thing. Same as "cin" too. I understand the "using namespace std;".
Last edited on
using std::cout; allows you to write cout instead of std::cout. I don't personally find it very useful. Much easier to just write std::cout everywhere.
can't you simply type "using namespace std;" to clear it up?
@DetectiveRawr
can't you simply type "using namespace std;" to clear it up?


You can. But in this case you introduce all names from the namespace std into the global namespace. It can result in name conflicts. But in such simple programs as yours there are no any problem.
Last edited on
Topic archived. No new replies allowed.