Thread: how to line change in a console application

  1. #1
    new2c++
    Guest

    how to line change in a console application

    how to change a line in a console application?

    #include <iostream.h>

    int main ()
    {
    cout << "first line";
    cout << "second line";
    cout << "and last line"<<endl;
    int exit;
    cin >> exit;
    return 0;
    }


    This will only be 1 whole line, can anyone explain to me how to get the lines seperated?

    thanks

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    You need to break the lines using endl


    Code:
     #include <iostream.h> 
    
     int main () 
    { 
    cout << "first line" << endl;
    cout << "second line" << endl;
    cout << "and last line"<<endl; 
    int exit; 
    cin >> exit; 
    return 0; 
    }
    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 to save time put a '\n' in there,

    EG:
    PHP Code:
    cout << "Firstline\nSecondline";

    OR

    cout << "Firstline\n";
    cout << "Secondline"

  4. #4
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    I think it would be better for him/her to use endl because it clears the buffer so he/she doesn't have to worry about those problems so early.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making a stealthy win32 console application?
    By killdragon in forum C++ Programming
    Replies: 3
    Last Post: 09-08-2004, 02:50 PM
  2. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  3. Visual C++ 6.0 Console Application
    By satch in forum Windows Programming
    Replies: 1
    Last Post: 12-25-2001, 07:55 PM
  4. Validating the contents of a char buffer
    By mattz in forum C Programming
    Replies: 3
    Last Post: 12-09-2001, 06:21 PM