Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > string stream question

Reply
Thread Tools

string stream question

 
 
JM
Guest
Posts: n/a
 
      09-13-2004
Hi,


If you change the same string stream to a new string, why is it that
you have to .clear() it before using it? If I don't I get garbage.

Thanks,
Jason

ex.

string a = "12";
string b = "15";
float fa,fb;

istringstream is;

is.str(a);

is>>fa;

is.clear( ) // must do this....

is.str(b)

is>>fb




 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      09-13-2004
JM wrote:
> Hi,
>
>
> If you change the same string stream to a new string, why is it that
> you have to .clear() it before using it? If I don't I get garbage.
>
> Thanks,
> Jason
>
> ex.
>
> string a = "12";
> string b = "15";
> float fa,fb;
>
> istringstream is;
>
> is.str(a);
>
> is>>fa;
>
> is.clear( ) // must do this....
>
> is.str(b)
>
> is>>fb



It probably because changing strings is not coupled with clearing
any errors. The state of the stream is still "end-of-file", which
you have to clear before you can read again.

Victor
 
Reply With Quote
 
 
 
 
JM
Guest
Posts: n/a
 
      09-13-2004
On Mon, 13 Sep 2004 16:45:33 -0400, Victor Bazarov
<(E-Mail Removed)> wrote:


>
>It probably because changing strings is not coupled with clearing
>any errors. The state of the stream is still "end-of-file", which
>you have to clear before you can read again.
>
>Victor


That makes sense, thanks Victor.

-JM

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert DVD with subtitle stream to DivX with same subtitle stream(selectable) malise Software 1 04-17-2007 09:15 AM
what is the different between byte stream and character stream? dolphin Java 6 03-18-2007 01:58 PM
get stream mode flags from an opened stream Alexander Korsunsky C++ 1 02-17-2007 10:38 AM
How to GET multi-word input from a *file* stream as opposed to a *console* stream? sherifffruitfly@gmail.com C++ 9 04-27-2006 04:14 PM
Doing readline in a thread from a popen4('rsync ...') stream blocks when the stream ends. Rasmusson, Lars Python 1 04-30-2004 08:10 AM



Advertisments