Thread: Stop from bypassing string input?

  1. #1
    Registered User
    Join Date
    Mar 2005
    Location
    Freeport, IL
    Posts
    32

    Stop from bypassing string input?

    Alright I have these basic lines of code:

    Code:
    cout << "Enter a Number:  ";
        cin >> number;
    
        cout << "What is your name: ";
        cin.getline ( name, 300, '\n' );
    My program stops after the first cout line and waits for input, I put the info in and hit enter, it then prints out the next cout line but does not stop to get the input from the user.

    What do I need to do here to get it to stop and wait for the input of the name?

    Thanks

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Either don't mix cin >> and cin.getline, or call cin.ignore(1000, '\n') after cin >> number.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Freeport, IL
    Posts
    32
    Works perfectly,

    Thanks a lot for the quick reply.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 14
    Last Post: 01-18-2008, 04:14 PM
  2. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  3. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  4. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM
  5. Basic C Programming Help Needed
    By Smurphygirlnz in forum C Programming
    Replies: 8
    Last Post: 09-26-2002, 07:12 PM