I have this code in an Objective-C class (in an Objective-C++ file):
+(NSString *)readString
{
string res;
std::getline(cin, res);
return [NSString stringWithCString:res.c_str() encoding:NSASCIIStringEncoding];
}
When I run it, I get a zero-length string, Every time. Never given the chance to type at the command line. Nothing. When I copy this code verbatim into main()
, it works. I have ARC on under Build Settings. I have no clue what it going on. OSX 10.7.4, Xcode 4.3.2.
It is a console application.
std::cin
just in casecin
got shadowed? – Remaremaincin
have any error flags set on it? – Remaremaingetline
, it reads the newline and immediately returns, not allowing you to enter any input because it's already found the end of the line. – Ewall