Cout on more than one line

This is a discussion on Cout on more than one line within the C++ Programming forums, part of the General Programming Boards category; Is it possible to output data on more than one line or is it mandatory that each niew line of ...

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

    Cout on more than one line

    Is it possible to output data on more than one line or is it mandatory that each niew line of text be accompanied by a cout << statement. Thanks

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Do you mean -

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main ( ) {
      
    	cout << "This sentence"
    		" is on"
    		" more than one"
    		" line.";
    
      return 0;
    }
    or

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main ( ) {
      
    	cout << "This sentence\nis on\nmore than one\nline.";
    
      return 0;
    }
    ?

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    2
    #include <iostream.h>

    void main()
    {
    cout << "Hello "
    "this is perfectly "
    "alright";
    cout << "\nSo"
    << "is"
    << "this";
    }

  4. #4
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    oh so you can have more that one string on cout......interesting I wonders why books don't touch on this.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  5. #5
    Much older and wiser Fountain's Avatar
    Join Date
    Dec 2001
    Location
    Engeeeerland
    Posts
    1,158
    Thanks for the information there-even though it was not my question! I have 'removed' lots of cout << from my latest program code.....I never knew that...................used lots of \n but not the other way you described. Thanx
    Such is life.

  6. #6
    31173 h4x0r gnu-ehacks's Avatar
    Join Date
    Nov 2001
    Posts
    556
    Most books do tell you how to do this...Although it isn't very useful. You can just do this:

    cout << "hello" << " my" << " friend";
    What will people say if they hear that I'm a Jesus freak?
    What will people do if they find that it's true?
    I don't really care if they label me a Jesus freak, there is no disguising the truth!

    Jesus Freak, D.C. Talk

    -gnu-ehacks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading a buffer line by line, while using system read
    By Hammad Saleem in forum C Programming
    Replies: 9
    Last Post: 05-27-2008, 06:41 AM
  2. Read only one line using seekg
    By RedZippo in forum C++ Programming
    Replies: 3
    Last Post: 03-31-2004, 11:10 PM
  3. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM
  4. SSCANF help
    By mattz in forum C Programming
    Replies: 7
    Last Post: 12-10-2001, 04:53 PM
  5. Validating the contents of a char buffer
    By mattz in forum C Programming
    Replies: 3
    Last Post: 12-09-2001, 06:21 PM

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