Find the answer to your Linux question:
Results 1 to 8 of 8
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    cout undeclared error

    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
    St. Petersburg, FL
    I'm assuming that you do have it inside a main() function?

  3. #3
    okay so this is my lil program...

    #include <iostream>
    cout<<"\nHello world";

    When I compile using gcc or g++


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

  4. $spacer_open
  5. #4
    Linux User
    Join Date
    Oct 2004
    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

  6. #5
    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<<"(...)")

  7. #6
    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

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

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

    #include <iostream>
    using namespace std;
    int main &#40;&#41;
       cout<<"Hello, world.\n";
       return 0;
    Registered Linux user #270181

  9. #8
    nope...that wuz the second version of my throws the same error...


    i compiled using
    $g++ -o hello

Posting Permissions

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