Find the answer to your Linux question:
Results 1 to 8 of 8
hi... can some1 help me out with this... when i try to compile a simple program using gcc,g++ or c++ i get the error saying "cout undeclared (use the function ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2005
    Posts
    11

    cout undeclared error


    hi...
    can some1 help me out with this...
    when i try to compile a simple program using gcc,g++ or c++ i get the error saying "cout undeclared (use the function first)"

    if you suggest corrections based on the namespace concept, i've tried it all...
    using namespace,std::cout...

    still don't seem to work...could it be a problem with the way the compiler is looking for the header files...i included both iostream and iostream.h...but it still is not compiling successfully...pls help!

  2. #2
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    Location
    St. Petersburg, FL
    Posts
    5,035
    I'm assuming that you do have it inside a main() function?

  3. #3
    Just Joined!
    Join Date
    Aug 2005
    Posts
    11
    okay so this is my lil program...

    #include <iostream>
    main()
    {
    cout<<"\nHello world";
    }

    When I compile using gcc or g++

    $gcc hello.cc

    I get the error mentioned above. I tried adding the line "using namespace std;". It wuz no good.

  4. #4
    Linux User
    Join Date
    Oct 2004
    Location
    /dev/random
    Posts
    404
    gcc with its default configuration is a C compiler and not C++ compiler.
    You should use g++ for compiling C++ programs.
    The Unforgiven
    Registered Linux User #358564

  5. #5
    Just Joined!
    Join Date
    Aug 2005
    Posts
    19
    You must use the namespace std in your program to output with cout

    either add

    using namespace std;

    after libraries includes or redirect cout to the std namespace ( std::cout<<"(...)")

  6. #6
    Just Joined!
    Join Date
    Aug 2005
    Posts
    11
    got it working on g++.
    But since the ".h" part was deprectaed from the specification, I keep getting the warning when I compile. This I avoided by "-Wno-deprecated" option as advised by the compiler. When I exclude the ".h" from the header file

    Code:
    #include <iostream>
    the error recurs.[/quote]

  7. #7
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    Just out of curiosity, does this version of Hello, world compile for you?

    Code:
    #include <iostream>
    using namespace std;
    
    int main &#40;&#41;
    &#123;
       cout<<"Hello, world.\n";
       return 0;
    &#125;
    Registered Linux user #270181
    TechieMoe's Tech Rants

  8. #8
    Just Joined!
    Join Date
    Aug 2005
    Posts
    11
    nope...that wuz the second version of my program...it throws the same error...

    COUT IS UNDECLARED

    i compiled using
    $g++ -o hello hello.cc

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •