Thread: skipping lines

  1. #1
    Registered User
    Join Date
    Sep 2003

    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:
    #include <iostream>
    using namespace std;
    int main() 
      int num;
      int num2;
      cout<<"Hello There!";
      cout<<"What is your favorite number?";
      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
    Seattle, WA
    Simple problem:
    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."

  3. #3
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    You could do:
    cout<<"Hello There!" << endl;
    That will put a newline after the preceding
    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