This is a discussion on cin.get(); within the C++ Programming forums, part of the General Programming Boards category; Is this command: cin.get(); compiler specific?? because I have been hunting high and low for a way to make my ...

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005


    Is this command: cin.get(); compiler specific?? because I have been hunting high and low for a way to make my screen oause without using system("pause"). I have tryed all the following:


    the only one that works is getch(), but I get warnings about using it, I am using Microsoft Visual 2005 beta compiler now, and on my old DevC++ compiler which I still have as backup, all the above work apart from cin.get. What should I do?
    I have looked at the FAQ and googled it, I know I can use getch() for now, but there must be another command I can use apart from system("pause"), which is frowned apon

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    std::cin.get() is part of the C++ standard library.

    As for your answer, it can be found by searching, and might result in you finding a thread like this one.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2005
    get() is a member function of basic_istream, so cin.get() is legal. Similarly for cin.sync(). get() returns the next byte in the stream. cin.get() won't do what you want though, as it treats the standard input like a file. In other words, if the user types ABC<enter> it will return 'A' [or, more accurately, the integer value associated with 'A'] after the <enter> is hit. If cin.get() is called again, with no other operations that get input from cin, the next call will return 'B' .

    get.char() is meaningless, as char is a keyword.

    getch() will do what you want, but is compiler dependent. Unfortunately, there is no equivalent function supported in either the C or C++ standards. The reason for this is that such functions assume a computer with a keyboard to get keystrokes from, and both C and C++ are designed to work on machines that don't necessarily have a keyboard.

    system("pause"); is not specifically frowned upon because it is compiler dependent. It only works with Microsoft operating systems under certain conditions (eg if the user installs a different command interpreter it won't necessarily work). In other words, depending on how the system is set up, it won't work ..... which is not exactly a good idea if you are providing software to people and can't control how they set up their operating system.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cin.get(); not working with my switch statement
    By tenor_jazz13 in forum C++ Programming
    Replies: 2
    Last Post: 01-12-2008, 09:33 PM
  2. cin.get() problem
    By Cilius in forum C++ Programming
    Replies: 20
    Last Post: 07-28-2005, 05:32 PM
  3. Confused about cin.get(); and classes.
    By RaccoonKing in forum C++ Programming
    Replies: 6
    Last Post: 07-17-2005, 11:44 AM
  4. cin.get() aint working.
    By Blips in forum C++ Programming
    Replies: 19
    Last Post: 01-17-2005, 05:55 PM
  5. curiosity about cin.get() and cin.getline()
    By ssjnamek in forum C++ Programming
    Replies: 18
    Last Post: 11-30-2003, 12:26 AM

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