473,799 Members | 2,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Interleaving iostream read and write

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::stringstre am 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
Aug 13 '05 #1
0 1660

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2642
by: Tom Plunket | last post by:
I find myself often doing the following sort of thing (sorry for lack of whitespace, I don't want the line to break): for entry, index in map(lambda e,i:(e,i),aList,range(len(aList)): # ... This definitely seems like a roundabout way to loop through parallel lists together. Is this map routine truly the easiest/ best/most straight-forward way to do a for loop through parallel lists, if I feel that the Python anti-idom of:
19
3847
by: ernst.stiegler | last post by:
Hello, I just want to read a whole line from a console input. What I don't understand is that I always have to press ENTER twice in order to see the line I've entered. Here's my code : #include <string> #include <iostream>
20
5547
by: Mark | last post by:
I am using gnu g++ version 3.3.2, trying a simple test to read in and then write out a large (100,000 line) text file ########################################## CSTDIO VERSION TO READ/WRITE TEXT FILE: #include <cstdlib> #include <cstdio> using namespace std;
3
6852
by: garyatusa | last post by:
Hi, there, I need to put a bunch of data to an iostream, or a buffer sequencially for each object, and write them to a file in specific sequence. I couldn't find any helpful information how to do that. If iostream is not the best way, how to do it. I don't know the size of the object. Your time and help are highly appreciated. Following is the structure stripped off unnecessary parts: class Base
1
3158
by: mathieu | last post by:
Hello, I am working on a project where I need to serialize my objects to a stream in a mixed ASCII/binary way. Using the c++ iostream was extremely straighforward and I quickly made progress. Unfortunately I need to handle endianess (reading big endian binary file on little endian architecture and vice versa). In order to do that I copy paste a hierachy-like structure for my own IOStream. Basically I have (*) All I need to do then is to...
1
1566
by: estebistec | last post by:
Hello, I've developed a CompositeControl in C# for ASP.NET 2.0. In this control I am simulating Edit and View modes by hiding or showing appropriate controls (setting Control.Visible). Basically I'm simulating the functionality of the DetailsView or a GridView cell, except that my data is dynamic (variable number of fields), so I can't just use those. So I have custom edit and view controls for this dynamic data and I render one of...
4
2660
by: Herman.Schultz | last post by:
Hi, How can I use iostream library in c++ to copy a file from i th byte to an output file? Thank you.
5
1627
by: sudhivns | last post by:
Hi, I wann use the same collection in interleaving loops. like F1(..) { foreach(child prd in parent) F2(prd ) }
19
7382
by: Robert Kochem | last post by:
Hi, I am relative new to C++ regarding it's functions and libraries. I need to access files larger than 4GB which is AFAIK not possible with the STL iostream - at least not if using a 32 bit compiler. iostream was my favorite as my code has to work on files as well as memory buffers... Could somebody please help me what functions/classes are the best in this case?
0
9550
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10269
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4148
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2942
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.