cin.get() pauses the program?

This is a discussion on cin.get() pauses the program? within the C++ Programming forums, part of the General Programming Boards category; Hi, I've run into a problem, I have a switch-statement like this: Code: switch(chMenu) { case 1: //Code break; case ...

  1. #1
    the Wizard
    Join Date
    Aug 2004
    Posts
    109

    cin.get() pauses the program?

    Hi,

    I've run into a problem,

    I have a switch-statement like this:
    Code:
    switch(chMenu)
    {
     case 1:
      //Code
     break;
     
     case 2:
      //code
      cout << "Press a button to continue.." << endl;
      cin.get();
     break;
    }
    Shouldn't the cin.get(); pause the program until the uses presses a button?

    Does anybody have a solution to the problem?
    Anything but system("pause");
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,803
    Its probably because you are using a cin>> before your cin.get(). cin>> leaves the '\n' in the input stream and your cin.get() picks up on it.
    Read This lovely tip:
    http://www.cprogramming.com/tips/sho...ount=30&page=0
    Woop?

  3. #3
    the Wizard
    Join Date
    Aug 2004
    Posts
    109
    Oh..
    Didn't knew that.
    Thx alot
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,803
    You are quite welcome.
    Woop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  3. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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