cout'ing to a new line

This is a discussion on cout'ing to a new line within the C++ Programming forums, part of the General Programming Boards category; I occasionally want 'cout' to give me a new line. actually, pretty often . How can I do that? I ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    1

    cout'ing to a new line

    I occasionally want 'cout' to give me a new line. actually, pretty often . How can I do that? I know that I can 'putchar(10)', however, this way requires me to do one right after every line of text... it's just not too short.

    Here's an example of what I have:
    Code:
    	cout << "What is your account type? Possible types:";
    	cout << "-----------------------------------";
    	cout << "| Account Type		| Interest |";
    	cout << "|----------------------|-----------";
    	cout << "|1) personal finance	| 2.3% 	   |";
    	cout << "|2) personal homeowner	| 2.6%	   |";
    	cout << "|3) personal gold	| 2.9%	   |";
    	cout << "|4) small business	| 3.3%	   |";
    	cout << "|5) big business	| 3.5%	   |";
    	cout << "|6) gold business	| 3.8%	   |";
    	cout << "|_________________________________|";
    of course, when I print this I assumed that doing another 'cout' would start a new line, but it hasn't...

    just in case it matters, i'm using g++ on a linux x86 system

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Put a \n directly in the text where you want the newline, or cout << endl;

    cout << "What is your account type? Possible types:\n";
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    or you could use endl;

    ex:

    cout << "What is your account type? Possible types:" << endl;
    "There are three kinds of people in the world...
    Those that can count and those that can't."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading a file line by line
    By Raskalnikov in forum C Programming
    Replies: 8
    Last Post: 03-19-2009, 12:44 AM
  2. Pointer and Polymorphism help.
    By Skyy in forum C++ Programming
    Replies: 29
    Last Post: 12-18-2008, 09:17 PM
  3. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 04:13 PM
  4. Finding carriage returns (\c) in a line
    By JizJizJiz in forum C++ Programming
    Replies: 37
    Last Post: 07-19-2006, 06:44 PM
  5. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 09:45 PM

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