Thread: total noob with a problem

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    3

    Lightbulb total noob with a problem

    hey im totally new to all this programing stuff but im trying to learn. Im working from a SAMS book on C++ and for one exercise i have to type in the following code:

    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;
    }
    I get these error messages using Microsoft Visual C++ 2005

    Code:
    error C2065: 'endl' : undeclared identifier
    
    error C2065: 'end' : undeclared identifier
    any help would be appreciated as i am pretty sure i have typed it all in right! thanks.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    endl is in the std namespace so you need to do
    Code:
    std::endl
    As you've done with cout. End looks like a typo.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    both of them should be std::endl instead
    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

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    3
    yea I tried that and it worked thanks but why does the book not include what you said then?

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    or you can just use
    Code:
    using namespace std;
    above your int function and then you wont have to use
    Code:
    std::cout
    just
    Code:
    cout
    .

    It think thats easier to learn.

    Quote Originally Posted by dwainpipe
    yea I tried that and it worked thanks but why does the book not include what you said then?
    because the book, uses
    Code:
    std::cout <<"\n";
    instead of what you typed.
    Code:
    "\n";
    gives you basically the same effect as
    Code:
    endl
    you are still on page 21 of the book, you need to read a bit more of the book and you will find the differences.
    Last edited by InvariantLoop; 03-07-2006 at 07:45 AM.
    When no one helps you out. Call google();

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    3
    page 23 actually, but thanks for the useful info!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. Undefined Symbol problem
    By Duskan in forum C Programming
    Replies: 2
    Last Post: 05-20-2007, 04:01 AM
  3. Total noob in OpenGL...
    By LegendBreath in forum Game Programming
    Replies: 3
    Last Post: 04-19-2005, 01:34 PM
  4. noob problem with a number generator
    By Amoreldor in forum C Programming
    Replies: 14
    Last Post: 03-10-2005, 10:39 AM
  5. Problem with calculations
    By 3901LV in forum C Programming
    Replies: 2
    Last Post: 03-03-2005, 02:07 PM