Thread: Help with this.

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    15

    Help with this.

    Ok I just bought Sams learn C++ In 21 days. So happy, since it got so many good reviews on C++ sites. Anyways!
    I'm using the DEV-C++ compiler and ran into this. x_x;

    C:\DOCUME~1\Slash\LOCALS~1\Temp\cc0Kcaaa.o(.text+0 x24):hello.cpp: undefined reference to `cout'
    C:\DOCUME~1\Slash\LOCALS~1\Temp\cc0Kcaaa.o(.text+0 x29):hello.cpp: undefined reference to `ostream:perator<<(char const *)'

    I get those errors while using these codes.

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

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It works for me. Which version of Dev-C++ are you using? Use version 4.9.9.2.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    15
    Quote Originally Posted by laserlight View Post
    It works for me. Which version of Dev-C++ are you using? Use version 4.9.9.2.
    Oh yes I am. Thank you <3.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    So... are you still having a problem with the code? If you do, the next possible reason is that you have not placed it in a project.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Dev-C++ should be able to compile non-projected files too...
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Already using namespace due to the "std::"

  7. #7
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Yeah, sorry, I never notice things.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  8. #8
    Registered User
    Join Date
    Oct 2007
    Posts
    15
    Another error! but I retyped the program code correct completely from the book.

    Code:
    #include <iostream>
    int main()
    {
    
        int x = 5;
        int y = 7;
        std::cout << endl;
        std::cout<< x + y << " " << x * y;
        std::cout<< end;
        char response
        std::cin >> response;
        return 0
    }
    7 C:\Documents and Settings\Slash\Desktop\ebay pics\HELLO.cpp `endl' undeclared (first use this function)

    The error ^

    Sorry e e;.

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    endl is a member of the std namespace.

  10. #10
    Registered User
    Join Date
    Oct 2007
    Posts
    15
    Quote Originally Posted by Daved View Post
    endl is a member of the std namespace.
    I am using std namespace.

  11. #11
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    No you ain't. You got to use endl exactly like cout or cin. So it would be:
    Code:
    #include <iostream>
    int main()
    {
        int x = 5;
        int y = 7;
        std::cout << std::endl;
        std::cout<< x + y << " " << x * y;
        std::cout<< std::endl;
        char response
        std::cin >> response;
        return 0
    }
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  12. #12
    Registered User
    Join Date
    Oct 2007
    Posts
    15
    Quote Originally Posted by maxorator View Post
    No you ain't. You got to use endl exactly like cout or cin. So it would be:
    Code:
    #include <iostream>
    int main()
    {
        int x = 5;
        int y = 7;
        std::cout << std::endl;
        std::cout<< x + y << " " << x * y;
        std::cout<< std::endl;
        char response
        std::cin >> response;
        return 0
    }
    Great that means, this book contains errors.

    Good reviews on a book that contains errors. T___T greattt.
    Last edited by Validinfection; 11-03-2007 at 03:30 PM.

  13. #13
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Which version?

    The 5th edition appears to have that fixed.

    Here's an errata if you're interested: http://www.libertyassociates.com/pag...hbook_edit.htm

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    #include <iostream>
    int main()
    {
    
        int x = 5;
        int y = 7;
        std::cout << endl;
        std::cout<< x + y << " " << x * y;
        std::cout<< end;
        char response;
        std::cin >> response;
        return 0
    }
    Forgot a ; after char response.
    Btw, you can also tell the compiler you're using a namespace without typing it by using
    Code:
    using namespace my_namespace;
    So
    Code:
    using namespace std;
    Then there's no need to type std:: before every function and constant in that namespace.
    Good luck.

  15. #15
    Registered User
    Join Date
    Oct 2007
    Posts
    15
    Quote Originally Posted by Daved View Post
    Which version?

    The 5th edition appears to have that fixed.

    Here's an errata if you're interested: http://www.libertyassociates.com/pag...hbook_edit.htm
    Really?.. I have the Fifth edition.

    It's under Exercises (First one.)

    and it is written
    Code:
    #include <iostream>
    int main()
    {
       int x= 5;
       int y= 7;
     std:: cout << endl;
     std:: cout << x+y << x*y;
     std:: cout << end;
     return= 0;
    }

Popular pages Recent additions subscribe to a feed