input = new char[64]();
std::cout << "wait for cin" << std::endl;
while (std::cin >> std::setw(64) >> input)
{
std::cout << "input : " << input << std::endl;
...
Well I assure you setw()
copies 63 characters to the char * input
instead of 64 and I see the 64rth character displayed on the next while(cin) iteration. Can this behavior be overridden ? I want all my 64 chars and NO nul
in my array.
operator>>(istraem&, char*)
will always write the nul byte.C++2003, 27.6.1.2.3/7 (emphasis added):
You can get nearly the behavior you want
setw(65)
, orstd::cin.read(input, 64)
.Note that the two solutions are not identical. Using
std::cin >> input
treats whitespace differently thanstd::cin.read()
does.