In xcode 4.3 I have set the project to use c++11: I changed the voice c++ language dialect to c++11, and c++ standard library to “libc++ ( LLVM c++ standard library with c++11 support)”.
Then I tried to compile and execute this simple code:
#include <iostream>
using namespace std;
int main (int argc, char** argv)
{
char buffer[100];
cin.getline(buffer,100);
cout << buffer << endl;
return 0;
}
The problem is that it asks two times the input.For example I type “hello” and the stream remains opened, waiting for another string.If I type another string then it prints out “hello”.
If I don’t use c++11 this problem doesn’t occur.
Does anyone know how to solve this problem? I want to take in input maximum 100 characters without using std::string.
This is a bug in libc++. My apologies. It is fixed on Mountain Lion. You can work around it by using
getline(istream&, string&)instead: