Thread: Problem with "cin.get()"

  1. #1
    Registered User
    Join Date
    Oct 2010

    Problem with "cin.get()"

    Hi, everyone!

    I'm just starting to learn C++. I wrote this basic program, but it's closing before I can see the output. The "cin.get()" line doesn't seem to be working. What am I doing wrong?


    #include <iostream>
    using namespace std;
    int main()
        int a;
        cout<<"Hey! What's your favourite digit?\n";
        cin>> a;
        cout<<"You entered: "<< a<<"\n";

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Cambridge, UK
    Have a research on cin.ignore() method

    And also search the board. 1000's of post on this topic

    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  3. #3
    Registered User helloalyssa's Avatar
    Join Date
    Sep 2010
    you need to put cin.ignore() before cin.get().

  4. #4
    Registered User
    Join Date
    Nov 2003
    Quote Originally Posted by helloalyssa View Post
    you need to put cin.ignore() before cin.get().
    Thank you
    It solved my problem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM