Thread: Problem with cout

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    2

    Angry Problem with cout

    I'm new to this so I was starting the tutorial and on lesson one I found something wrong. I found out first mistake was <iostream.h>
    Program: Test.cpp
    #include <_iostreamP.h>

    int main()

    {

    cout<<"HEY, you, I'm alive! Oh, and Hello World!";

    return 0;

    }

    Once I compiled it I got this error message:

    In function 'int main()':
    Test.cpp(7) Error: 'cout' undeclared (first use this function)
    Test.cpp(7) Error: (Each undeclared indentifier is reported only once for each function in appears in)

    Thanks for all your help. Trevor

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    The 'include' is <iostream.h>.

    Or, #include <iostream> coupled with 'std::cout' vice 'cout', i.e.:
    Code:
    #include <iostream>
    
    int main()
    {
    std::cout << "HEY, you, I'm alive! Oh, and Hello World!";
    
    return 0;
    }
    -Skipper
    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    2
    Thank you Skipper That worked thanks again. Trevor

  4. #4
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    *Grabs fire suit*
    The best way is like this:
    Code:
    #include <iostream.h>
    
    int main()
    {
        cout << "Hello";
    
        return 0;
    }

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    face_master, if by best you mean non-standard then you are correct. skipper's example is correct. You can also do this:

    Code:
    #include <iostream>
    
    int main()
    {
        using std::cout;
        cout << "HEY, you, I'm alive! Oh, and Hello World!";
        cout << "I'm using cout without typing 'std::' every time";
    
        return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getline problem
    By ktar89 in forum C++ Programming
    Replies: 3
    Last Post: 06-24-2007, 06:47 AM
  2. Cout redirection problem
    By MrLucky in forum C++ Programming
    Replies: 6
    Last Post: 06-06-2007, 11:11 AM
  3. cout problem with windows API
    By xximranxx in forum Windows Programming
    Replies: 2
    Last Post: 05-04-2007, 12:37 AM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Weird Problem
    By Xeavor in forum C++ Programming
    Replies: 14
    Last Post: 11-20-2004, 11:23 AM