Simple cout query from a newbie

This is a discussion on Simple cout query from a newbie within the C++ Programming forums, part of the General Programming Boards category; Just going through a tutorial and saw this code Code: cout << "Here is 5: " << 5 << "\n"; ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    12

    Simple cout query from a newbie

    Just going through a tutorial and saw this code

    Code:
    cout << "Here is 5: " << 5 << "\n";
    And heres a quote about it

    Next, the value 5 is passed to the insertion operator and the newline character (always in double quotes or single quotes).
    Is there any reason why you would just do this?

    Code:
    cout << "Here is 5: " << "5\n";
    Or is the book I have just being an ass?

  2. #2
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    or for that matter

    cout << "Here is 5: 5\n";

    the book is showing that not just strings, but ints can also be displayed by cout
    hello, internet!

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    12
    I see that does seem to be the case as it goes on to show how you can do additions and other similar things aswell

  4. #4
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    another example would be
    Code:
    int x;
    x = 5;
    cout << "here is the value of x: " << x;

  5. #5
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    another example could be:

    Code:
    cout << "2 + 2 = " << 2 + 2 << '\n';
    Couldn't think of anything interesting, cool or funny - sorry.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. probably something simple I'm overlooking
    By tomasc in forum C++ Programming
    Replies: 3
    Last Post: 05-20-2008, 12:07 AM
  2. Need Help with a Bowling Score Program
    By oobootsy1 in forum C++ Programming
    Replies: 6
    Last Post: 11-01-2005, 10:04 AM
  3. Newbie programmer, few quick questions...
    By cjmdjm in forum C++ Programming
    Replies: 1
    Last Post: 10-29-2005, 11:51 PM
  4. Newbie! Help With Two Simple C++ Programs.
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 09-06-2005, 09:38 AM
  5. Replies: 3
    Last Post: 11-04-2001, 03:53 PM

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