Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: cout issue

  1. #11
    Join Date
    Aug 2006
    Beans
    140

    Re: cout issue

    Quote Originally Posted by Zugzwang View Post
    Are you sure that you pasted the correct contents of "hello.cpp"? Your compilation error message says that "cout" was not declared in line 6, but line 6 is actually "return 0;". Is it possible that in fact your IDE tries to compile your old code?
    Hmmmm not sure, I'll try again deleting everything and creating a new project and let you know.

  2. #12
    Join Date
    Aug 2006
    Beans
    140

    Re: cout issue

    Right tried again, I had it set to Build Automatically so didn't get the build error but got the error

    Description Resource Path Location Type
    Symbol 'cout' could not be resolved brandnew.cpp /Brand New line 5 Semantic Error

    Code I used was
    Code:
    #include <iostream>
    
    int main()
    {
        std::cout << "Hello World!\n";
        return 0;
    }

  3. #13
    Join Date
    Apr 2012
    Beans
    5,575

    Re: cout issue

    Quote Originally Posted by toontastic View Post
    Right tried again, I had it set to Build Automatically so didn't get the build error but got the error

    Description Resource Path Location Type
    Symbol 'cout' could not be resolved brandnew.cpp /Brand New line 5 Semantic Error


    Code I used was
    Code:
    #include <iostream>
    
    int main()
    {
        std::cout << "Hello World!\n";
        return 0;
    }
    So you are using some kind of IDE (code::blocks maybe?) - what happens if you just open a terminal, cd to the directory containing the file 'brandnew.cpp', and try to compile and link on the command line

    Code:
    g++ -o brandnew brandnew.cpp

  4. #14
    Join Date
    Aug 2006
    Beans
    140

    Re: cout issue

    Ok I did

    cd Brand\ New

    Then I wrote

    g++ -o brandnew brandnew.cpp

    and I got no response at all. So I tried

    g++ -o brandnew.cpp

    and I got the error
    Code:
    g++: fatal error: no input files
    compilation terminated.

  5. #15
    Join Date
    Apr 2012
    Beans
    5,575

    Re: cout issue

    g++ will give no response if compilation succeeds - basically that means there were no errors and it was able to resolve std::cout correctly

    Unfortunately

    Code:
    g++ -o brandnew.cpp
    probably overwrote your source code file (-o means output so it will try to create the executable program but give it the name 'brandnew.cpp' instead of plain 'brandnew')

    I suggest creating the .cpp file again, running

    Code:
    g++ -o brandnew brandnew.cpp
    and then checking if the executable was produced

    Code:
    ls -l
    and if so trying to run it

    Code:
    ./brandnew
    BTW if your IDE uses Makefiles under the hood you may run in to trouble if your build directory name contains spaces - just a heads up
    Last edited by steeldriver; November 24th, 2012 at 08:45 PM.

  6. #16
    Join Date
    Aug 2006
    Beans
    140

    Re: cout issue

    Quote Originally Posted by steeldriver View Post
    g++ will give no response if compilation succeeds - basically that means there were no errors and it was able to resolve std::cout correctly

    Unfortunately

    Code:
    g++ -o brandnew.cpp
    probably overwrote your source code file (-o means output so it will try to create the executable program but give it the name 'brandnew.cpp' instead of plain 'brandnew')

    I suggest creating the .cpp file again, running

    Code:
    g++ -o brandnew brandnew.cpp
    and then checking if the executable was produced

    Code:
    ls -l
    and if so trying to run it

    Code:
    ./brandnew
    BTW if your IDE uses Makefiles under the hood you may run in to trouble if your build directory name contains spaces - just a heads up

    Oooooo excellent that worked I was able to finally see Hello World!
    Ok I'll make sure I leave out the spaces now.

    Right it seems I've done something funny in terms of IDEs in Eclipse. Is there a way to fix this so I don't have to use terminal and can infact just run the programs in Eclipse ?

  7. #17
    Join Date
    Aug 2006
    Beans
    140

    Re: cout issue

    Ok very strangly after doing that in terminal it now builds fine and returns Hello World! in Eclipse as well now.

    Thank you all very much for your help.

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

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