Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Interleaving iostream read and write

Reply
Thread Tools

Interleaving iostream read and write

 
 
Garrett Kajmowicz
Guest
Posts: n/a
 
      08-13-2005
I have two implementations of stringstream and they both handle
interleaved reads and writes differently. I was hoping that you might be
able to shed some light as to the "correct" operation, and hopefully point
out in the standard where this mode of operation is specified.

Here is the test code:

std::stringstream a;
float f;
int i;
std::string s;

a.str("2.35 5 Test");

a >> f >> i >> s;

std::cout << "f (should be 2.35): " << f << std::endl;
std::cout << "i (should be 5): " << i << std::endl;
std::cout << "s (should be Test): " << s << std::endl;

a.clear();
std::cout << "Buffer after flag clear: " << a.str() << std::endl;

std::cout <<"Combining read and write activities\n";
a.str("Testing data");
s = "";
a << 2.5 << " ";
a >> s;
std::cout << "Read out: " << "'" << s << "'" << std::endl;
a >> s;
std::cout << "Read out: " << "'" << s << "'" << std::endl;
std::cout << "Current buffer value: " << a.str() << std::endl;


The first sample output I get is:
f (should be 2.35): 2.35
i (should be 5): 5
s (should be Test): Test
Buffer after flag clear: 2.35 5 Test
Combining read and write activities
Read out: 'Testing'
Read out: 'data2.5'
Current buffer value: Testing data2.5

The second sample output I get is:
f (should be 2.35): 2.35
i (should be 5): 5
s (should be Test): Test
Buffer after flag clear: 2.35 5 Test
Combining read and write activities
Read out: '2.5'
Read out: 'ing'
Current buffer value: 2.5 ing data

Thanks for the info as to the correct operation.

- Garrett Kajmowicz
 
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
Frame Relay fragmentation and interleaving Mikey Cisco 2 05-12-2006 04:49 AM
Semi OT: Mixing iostream and iostream.h red floyd C++ 3 03-08-2005 05:57 PM
iostream + iostream.h S. Nurbe C++ 7 01-15-2005 07:49 AM
is MS newer <iostream> is slower than older <iostream.h>? ai@work C++ 9 12-16-2004 08:21 PM
#include <iostream.h> or <iostream> John Tiger C++ 10 08-06-2003 01:30 PM



Advertisments