Page 1 of 1

need help with cin and blank inputs

Posted: Tue Jul 23, 2002 9:05 pm
by bundy
ok what seems to be tripping me up on a few of these contest is how to deal with a blank input such as a space or carraiage return. I am trying to use cin and can't seem to trap it.

I have tried

while(cin >> input)

but i loop forever.

Posted: Tue Sep 17, 2002 12:34 pm
by tenshi
look at this example :

char s[maxlen];
cin.getline(s,maxlen);
istrstream strin(s);
while(sin>>x) cout<<x<<endl;

Posted: Tue Sep 17, 2002 4:02 pm
by arnsfelt
or more robust:

[cpp]
string s;
getline(cin,s);
istringstream sin(s);
while(sin>>x) cout<<x<<endl;
[/cpp]