cout

This is a discussion on cout within the C++ Programming forums, part of the General Programming Boards category; I would like to output 3 lines, each on their own line, for example: Heading 1 | 2 | 3 ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    5

    cout

    I would like to output 3 lines, each on their own line, for example:
    Heading
    1 | 2 | 3
    x y z
    Does anyone know anyway to force a line break?
    Thanks, Torsin

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    16
    you can do
    Code:
    cout<<"blah"<<endl;
    or
    Code:
    cout<<"blah\n";
    both should work

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    162
    I would recommend the one with endl, becouse it also flushes the output buffer I think.
    We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    5

    Talking Thanks!!

    Wow! Impressed with quick reply, thanks

  5. #5
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    to clarify what Aidman said, '\n' will add a new line to the buffer, but in C++, the contents of the stream aren't output until the buffer is full, so you might get strange results (something else may print in the middle, I had this happen for the first time recently).

    endl flushes the buffer, which causes it to be output to the screen.
    Thor's self help tip:
    Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

    OS: Windows XP
    Compiler: MSVC

  6. #6
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    yes use endl, very wise thing
    if you dont believe us about the buffer try using '\n' right before a getch() hehe.

    -LC
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. class methods to cout stream
    By shintaro in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2008, 06:27 PM
  2. cout vs std::cout
    By none in forum C++ Programming
    Replies: 10
    Last Post: 07-26-2004, 11:20 PM
  3. changing cout output
    By Yohumbus in forum C++ Programming
    Replies: 1
    Last Post: 10-23-2002, 04:09 AM
  4. Redirecting cout stream
    By Arrow Mk84 in forum C++ Programming
    Replies: 1
    Last Post: 10-08-2002, 04:17 PM
  5. printf vs cout
    By RyeDunn in forum C++ Programming
    Replies: 5
    Last Post: 07-09-2002, 04:26 PM

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