need help with cin and blank inputs

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

Moderator: Board moderators

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

need help with cin and blank inputs

Post 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.

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

Post by tenshi »

look at this example :

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

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

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

Post by arnsfelt »

or more robust:

string s;
istringstream sin(s);
while(sin>>x) cout<<x<<endl;

Post Reply

Return to “C++”