need help with cin and blank inputs

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
bundy
New poster
Posts: 10
Joined: Tue Jul 23, 2002 2:39 pm
Location: Findlay, Oh
Contact:

need help with cin and blank inputs

Post by bundy » Tue Jul 23, 2002 9:05 pm

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.

tenshi
New poster
Posts: 14
Joined: Tue Jun 25, 2002 8:50 am

Post by tenshi » Tue Sep 17, 2002 12:34 pm

look at this example :

char s[maxlen];
cin.getline(s,maxlen);
istrstream strin(s);
while(sin>>x) cout<<x<<endl;
http://www.ioiforum.org/en/

A problem discussing forum.
Welcome to discuss problems in it!

arnsfelt
New poster
Posts: 44
Joined: Wed Oct 17, 2001 2:00 am
Location: Denmark
Contact:

Post by arnsfelt » Tue Sep 17, 2002 4:02 pm

or more robust:

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

Post Reply

Return to “C++”