Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

toddburch

macrumors 6502a
Original poster
Dec 4, 2006
748
0
Katy, Texas
I have a C++ command line app, and when debugging it in Xcode, my cin.getline(char_array, some_byte_count) fails by looking like it took the input (the cin is no longer blocking), and cin.good() is set, but when I look at the debugger console, the char_array is un-initialized.

At first my project setting was 3.1.1 and that was REALLY screwing up by missing my break points. I started a new, clean project, copy/pasted all my code over (not that much) and went into Project Settings and picked Xcode 3.0. It worked a few times properly (the cin.getline() worked), but now it's not working. I've quit (completely) Xcode a few times, and each time now I get the same incorrect behavior.

Here's some sample code that fails: (pretty trivial stuff)
Code:
#include <iostream>

using namespace std ; 

int main (int argc, char * const argv[]) {
    int count ; 
	char filename[255] ; 
	count = 0 ; 
	cout << "Enter a file name" << endl ; 
	[color=red]cin.getline(filename, 255) ; [/color]
	if ( !cin.good() ) { 
		cout << "Error reading cin." << endl ; 
		return -1 ; 
	}
	cout << "File name is >" << filename << "<." << endl ; 
	return 0;
}
When you step thru it and get to the cin.getline(), press sihft+cmd+R to open the console, and then PASTE in a path, like /Users/me/Desktop/my.txt and see if you get the same problem.

It seems when I type data, all is OK, but when I paste data, that's when it fails.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.