Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 10, 2010, 12:45 PM   #1
Danksalot
macrumors newbie
 
Join Date: Jul 2010
C++ - Having trouble with cin >> in xCode...

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:


Code:
#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:
5
15
2546


x
b
5



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!

Danksalot
Danksalot is offline   0 Reply With Quote
Old Jul 10, 2010, 12:50 PM   #2
Matthew Yohe
macrumors Demi-God
 
Join Date: Oct 2006
Send a message via AIM to Matthew Yohe
Works here.

Have you updated XCode lately?
Matthew Yohe is offline   0 Reply With Quote
Old Jul 10, 2010, 01:06 PM   #3
Danksalot
Thread Starter
macrumors newbie
 
Join Date: Jul 2010
I just checked and I'm running xCode 3.1.4 on Leopard.

Looks like I'll have to get Snow Leopard to update any farther.

Last edited by Danksalot; Jul 10, 2010 at 01:20 PM.
Danksalot is offline   0 Reply With Quote
Old Jul 10, 2010, 01:10 PM   #4
Matthew Yohe
macrumors Demi-God
 
Join Date: Oct 2006
Send a message via AIM to Matthew Yohe
Quote:
Originally Posted by Danksalot View Post
I just checked and I'm running xCode 3.1.4 on Leopard.

I'll update to the latest version, then give it a try.
That's the latest version for Leopard. You need to update to Snow Leopard.
Matthew Yohe is offline   0 Reply With Quote
Old Jul 10, 2010, 01:13 PM   #5
chown33
macrumors 603
 
Join Date: Aug 2009
A specific problem with C++ streams, in Xcode debugger, Debug build.
Fix is to undefine Preprocessor Macros = _GLIBCXX_DEBUG=1 _GLIBCXX_DEBUG_PEDANTIC=1

http://forums.macrumors.com/showpost.php?p=8590820
.. the specific problem and fix.

Threads that discuss problem and fix:
http://forums.macrumors.com/showthread.php?t=867839
http://forums.macrumors.com/showthread.php?t=863761
http://forums.macrumors.com/showthread.php?t=837748
http://forums.macrumors.com/showthread.php?t=796818
http://forums.macrumors.com/showthread.php?t=780440
.. 867839 lists specific steps to take.
.. 796818 notes input problems.
chown33 is offline   0 Reply With Quote
Old Jul 10, 2010, 01:16 PM   #6
Matthew Yohe
macrumors Demi-God
 
Join Date: Oct 2006
Send a message via AIM to Matthew Yohe
I should've just searched here for that problem. I was Googling for Espinosa's thread on the XCode mailing list.
Matthew Yohe is offline   0 Reply With Quote
Old Jul 10, 2010, 02:32 PM   #7
Danksalot
Thread Starter
macrumors newbie
 
Join Date: Jul 2010
I had success locating those files, and I deleted them, and it still does not work. The program still runs exactly as I have described above. I also tried using #undef in my program to no avail.

Is there any way that I deleted them in the Edit Active Target menu and it didn't actually take them out?

Any other ideas?

I really appreciate your time and expertise!

Danksalot

Last edited by Danksalot; Jul 10, 2010 at 02:38 PM.
Danksalot is offline   0 Reply With Quote
Old Jul 10, 2010, 02:52 PM   #8
chown33
macrumors 603
 
Join Date: Aug 2009
File > New Project
Command Line Utility, C++ Tool

Edit main.cpp
I copy and paste your source code exactly.
Save.

"Debug" is active build configuration.
Build > Build. It builds.

Run > Run.
It runs.
It prompts "Enter a number:".
I press 5.
Press Return.
It prints "You entered: 5"
It exits.

Run > Run.
It runs.
It prompts "Enter a number:".
I press 5.
Press Enter. <--- DIFFERENT
Nothing.
Press Enter again.
Nothing.
Key in 33.
Press Return.
It prints "You entered: 33"
It exits.

Xcode 3.1.4. OS 10.5.8. Mac mini with Core 2 Duo.


Questions:
Are you hitting Return or Enter?
Are you running with Run or Debug?
Which build configuration?
chown33 is offline   0 Reply With Quote
Old Jul 10, 2010, 10:41 PM   #9
Danksalot
Thread Starter
macrumors newbie
 
Join Date: Jul 2010
I guess I thought I was using the RETURN key, but I was using the ENTER key every time. That solved my problem. Thanks a heap!

Danksalot
Danksalot is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
New to programming. Having trouble with Xcode chrisc23 Mac Programming 8 Nov 24, 2010 10:21 PM
New to programming, having trouble with xcode kevinlyman7 Mac Programming 4 Jul 31, 2010 09:51 AM
Having Trouble with Account Information In iTunes MacBOS Mac Applications and Mac App Store 0 Nov 23, 2009 02:43 AM
Having trouble with default save in transmission sabre364 Mac Applications and Mac App Store 1 Jul 17, 2009 10:48 PM
I'm having trouble with a basic concept - Switching views ethana iPhone/iPad Programming 2 Dec 31, 2008 08:37 AM


All times are GMT -5. The time now is 11:35 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC