I am using xCode on a Mac to write some c++ code.

Any time I use cin >> the program compiles just fine, but when I run it something happens that I didn't expect. I enter what I want for input and hit the RETURN key, and it goes to the next line, waiting for me to type something else. As far as I know, it should stop looking for input at that point, but it doesn't. Here's an example:

#include <iostream>

using namespace std;

int main()
    int Num = 0;
    cout << "Enter a number: " << endl;
    cin >> Num;
    cout << "You entered: " << Num << endl;
    return 0;

I never get to the "You entered: " statement, because I can't get it to assign the dang input! Anybody who knows what's going on, please let me know. Here's what the program looks like running:

Enter a number:


No matter what I enter, when I hit the RETURN key, it just goes to the next line and waits. Thanks in advance for any help!


I don't know the solutions to this.
(this is a friendly and discrete bump because I think it is an interesting issue)

I posted my questions over there too. Thanks for the link. I'll leave this up until somebody has an idea what may be going on.

Am I right that when the RETURN key is hit, it should go to the "cout <<" statement?

Yes it should. I recall Microsoft has a similar problem at one time with vc++ 6.0 compiler -- the problem was in a header file which they eventually fixed.

Turns out I was hitting the ENTER key, not the RETURN key. Something so simple. Thanks for thinking through this with me.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.