Thread: skipping lines

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    1

    skipping lines

    I just started up on programming in C++ from QBASIC and i was wondering how, when entering text, can u skip lines?

    When I put this in:
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main() 
    {
      int num;
      int num2;
      cout<<"Hello There!";
      cout<<"What is your favorite number?";
      cin>>num;
      cout<<"Your favorite number is: "<<num;
      return 0;    
    }
    It come out to:
    "Hello There!Whats your favorite number?"

    And I want it tho show:
    "Hellow There!"
    "Whats your favorite number?"

    Yeah im a newbie but ne help would be great!

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Simple problem:
    Code:
    ...
    cout<<"Some text..."<<std::endl; /*or just endl if you already have using namespace std at the top of your program*/
    cout<<"Some text on the next line\n";
    cout<<"\\n creates a new line as well!";
    Basically, you just need to add \n to the end of your text (within the quotes) or you can use endl, which also flushes the output buffer.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    You could do:
    cout<<"Hello There!" << endl;
    That will put a newline after the preceding
    OR:
    cout<<"Hello There!";
    cout<<"\nWhat is your favorite number?";

    Anywayzzz, FYI that was basic c++ that you should learn from available tutorial on this site.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 10-07-2008, 06:19 PM
  2. Print out first N lines
    By YoYayYo in forum C Programming
    Replies: 1
    Last Post: 02-21-2008, 12:58 AM
  3. Reading lines from a file
    By blackswan in forum C Programming
    Replies: 9
    Last Post: 04-26-2005, 04:29 PM
  4. count only lines of code...
    By flightsimdude in forum C Programming
    Replies: 13
    Last Post: 09-23-2003, 07:08 PM
  5. compiler skipping lines..?
    By Linette in forum C++ Programming
    Replies: 6
    Last Post: 04-12-2002, 11:59 PM