how to with a blank line input to terminate input

closed account (N8hM4iN6)
it's a for loop, in it i put a if statement, but i don't know how to judge whether it's a blank line.
And is it right i just strike the return key to make a blank line?

1
2
3
4
5
6
for (int i = 0; i < size; ++i)
{
  cin >> x[i];
  if (...)//what to put inside ()
    break;
}
Last edited on
Hi, if it is a string, you can check by using x[i].empty==0 . More information can be found in http://www.cplusplus.com/reference/string/string/empty/
@osgwsy: you need () for a function call.

You can use std::getline(std::cin, MyString) to get a full line. If MyString.empty() is true then you know it was a blank line.
Last edited on
closed account (N8hM4iN6)
wow, it works! : D

and what if it's a char* type rather than a string type, what member function should i use?

actually, the code above should be
cin >> x[i][20];
maybe cin >> x[i] make u think it's a string type : P
If it is a char*, you have no hope of ever doing it - it is completely impossible. I'm being serious - there is no way to know how much the user will type in so you can not know how large to make the buffer.
closed account (N8hM4iN6)
oic, thanks~
Topic archived. No new replies allowed.