total noob with a problem

This is a discussion on total noob with a problem within the C++ Programming forums, part of the General Programming Boards category; hey im totally new to all this programing stuff but im trying to learn. Im working from a SAMS book ...

  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
    22,268
    both of them should be std::endl instead
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 03:51 PM
  2. Undefined Symbol problem
    By Duskan in forum C Programming
    Replies: 2
    Last Post: 05-20-2007, 05:01 AM
  3. Total noob in OpenGL...
    By LegendBreath in forum Game Programming
    Replies: 3
    Last Post: 04-19-2005, 02: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21