Unusual Problem

This is a discussion on Unusual Problem within the Linux Programming forums, part of the Platform Specific Boards category; Here is my simple code. The problem occured in a much more difficult program, but this is the simplest example ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    1

    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.

    Code:
    // test.cpp
    #include<iostream>
    main()
    {
      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
    Location
    University of Waterloo
    Posts
    1,904
    Code:
    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
    Posts
    735
    The error is easy to fix.
    Code:
    #include<iostream>
    
    using std::cout;
    //alternatively
    //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, 05: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, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

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