std::cout

This is a discussion on std::cout within the C++ Programming forums, part of the General Programming Boards category; Just a quick question what does the std:: before cout or cin do for the rogram. I was told that ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    30

    std::cout

    Just a quick question what does the std:: before cout or cin do for the rogram. I was told that I didnt need that from someone but our teacher makes us use it. Dow anybody know if that is needed for a program to work or why he would make us use it if it isnt?

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    154
    You can use std::cout each time or you can declare it in either of two ways.
    Code:
    #include <iostream>    // Use this for both
    using std::cout;       // here's one way
    using namespace std;   // here's another
    
    int main()
    {
       cout << "Hello world!"; 
       return 0;
    }
    Using std::cout makes the file smaller, but you then have to declare similar things for every std class function you want to use, like cin, etc. The namespace way brings them all in. For more info on namespace & std, check posts for the last week or so,there's been threads on them there.

  3. #3
    Unregistered
    Guest
    Hi there!

    I recommend you using:

    #include <iostream.h>

    but not
    #include <iostream>
    using .....


    using namespaces for such things was supposed to be good style, but many programmers asured in the opposite...

    Ilia Yordanov,
    www.cpp-home.com ; C++ Resources
    loobian@cpp-home.com

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    154
    Originally posted by Unregistered
    Hi there!

    I recommend you using:

    #include <iostream.h>

    but not
    #include <iostream>
    using .....


    using namespaces for such things was supposed to be good style, but many programmers asured in the opposite...

    Ilia Yordanov,
    www.cpp-home.com ; C++ Resources
    loobian@cpp-home.com
    That way is ok, but the ANSI/ISO standard is <iostream>, and that's what most textx teach today.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cout and std::cout
    By alyeska in forum C++ Programming
    Replies: 15
    Last Post: 09-23-2007, 01:43 AM
  2. std::cout outputting in wrong order
    By nectodn in forum C++ Programming
    Replies: 2
    Last Post: 04-25-2006, 10:21 AM
  3. std::cout or using namespace std or using std::cout
    By ComDriver in forum C++ Programming
    Replies: 13
    Last Post: 01-31-2005, 11:54 AM
  4. cout vs std::cout
    By none in forum C++ Programming
    Replies: 10
    Last Post: 07-27-2004, 12:20 AM
  5. Whats the difference between cout and std::cout?
    By mdshort in forum C++ Programming
    Replies: 10
    Last Post: 12-30-2003, 05:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21