|
|
#1 |
|
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;
}
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 |
|
|
|
0
|
|
|
#2 |
|
Works here.
Have you updated XCode lately? |
|
|
|
0
|
|
|
#3 |
|
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. |
|
|
|
0
|
|
|
#4 |
|
|
0
|
|
|
#5 |
|
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. |
|
|
|
0
|
|
|
#6 |
|
I should've just searched here for that problem. I was Googling for Espinosa's thread on the XCode mailing list.
|
|
|
|
0
|
|
|
#7 |
|
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. |
|
|
|
0
|
|
|
#8 |
|
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? |
|
|
|
0
|
|
|
#9 |
|
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 |
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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:08 PM.








Linear Mode

