After using cin.clear internal state is set again back to goodbit, which means that there are no 'errors' If something is put on 'stream' (cin) then it must be taken from there. Using cin's >> operator will drop leading whitespace and stop input at the first trailing whitespace To grab an entire line of input, including spaces, try cin.getline(). Otherwise, use std::string instead of char[] To avoid that, you need to call cin.ignore() to discard any unread data.
Getting input from user using cin [duplicate] asked 15 years, 9 months ago modified 6 years, 11 months ago viewed 11k times Perhaps a better solution is to use std::getline() to read a of input, then use std::istringstream to read all of the numbers from that line into the vector. The program will also be outputting cin, cout, system не являются однозначными, как убрать ошибки? Вопрос задан 5 лет 11 месяцев назад Изменён 4 года 10 месяцев назад Просмотрен 73k раз A common problem while using getline with cin is getline does not ignore leading whitespace characters If getline is used after cin >>, the getline() sees this newline character as leading whitespace, and it just stops reading any further.
The only other question that i found asking this question is Ignore vs ws and it hasn't gotten much attention. Never use cin >> x Where x is a char* or a char array, without first setting the width on cin, using either the width member function, or the setw i/o manipulator.
OPEN