Thread: Unusual Problem

  1. #1
    Registered User
    Join Date
    Mar 2005

    Unusual Problem

    Here is my simple code. The problem occured in a much more difficult program, but this is the simplest example that I could generate.

    // test.cpp
      cout << "test\n";
    I am using the gnu g++ compiler under linux Mandrake 7.2. I used the following command to compile: g++ test.cpp

    The following error occured:

    test.cpp: In function `int main()':
    test.cpp:5: `cout' undeclared (first use this function)
    test.cpp:5: (Each undeclared identifier is reported only once for each function it appears in.)

    My first thought was that the header file was not within my path, but it was indeed there. I switched over to the <iostream.h> but I got a compiler warning about out of date header files that I was able to counteract by using the appropriate switch. This solution, does not lend itself to using the STL headers. Since I end up with a similar error for the STL functions and type definitions. Is there a compiler switch that needs to be used to use the up-to-date header files?

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    University of Waterloo
    using namespace std;
    Must be in there before the main function.

    Also, main should be int main

    And this belongs in the C++ forum.

  3. #3
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    The error is easy to fix.
    using std::cout;
    //using namespace std;
    int main()
      cout << "test\n";

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM