Problem with "cin.get()"

This is a discussion on Problem with "cin.get()" within the C++ Programming forums, part of the General Programming Boards category; Hi, everyone! I'm just starting to learn C++. I wrote this basic program, but it's closing before I can see ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    3

    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?

    Thanks

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

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

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

    ssharish
    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
    Posts
    25
    you need to put cin.ignore() before cin.get().

  4. #4
    Registered User
    Join Date
    Nov 2003
    Posts
    177
    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, 10: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

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