473,466 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

std string streams

Is there a string stream I can write into and read from?

I've tried std::stringstream but it won't let me read from it.

ie I can do this:

int iData = 123
std::stringstream ss;
ss << 123;

but not this afterwards:

int iDataReadFromStream;
iDataReadFromStream << ss;
Is there a data structure that allows me to do both?

thanks

Aug 9 '05 #1
5 1566
Dylan wrote:
ie I can do this:

int iData = 123
std::stringstream ss;
ss << 123;

but not this afterwards:

int iDataReadFromStream;
iDataReadFromStream << ss;


I'm no expert, but I'd say the latter doesn't work, because it calls the
<<-operator for int and not for stringstream.
Try:
ss>>iDataReadFromStream;

--
If geiger counter does not click,
the coffee, she is just not thick
Aug 9 '05 #2
On Tue, 09 Aug 2005 15:34:25 +0200, Sebastian Hungerecker
<se****@web.de> wrote:
Dylan wrote:
ie I can do this:

int iData = 123
std::stringstream ss;
ss << 123;

but not this afterwards:

int iDataReadFromStream;
iDataReadFromStream << ss;


I'm no expert, but I'd say the latter doesn't work, because it calls the
<<-operator for int and not for stringstream.
Try:
ss>>iDataReadFromStream;


that doesn't work either...
Aug 9 '05 #3
In message <lh********************************@4ax.com>, Dylan
<sp******@ontheball.com> writes
Is there a string stream I can write into and read from?

I've tried std::stringstream but it won't let me read from it.

ie I can do this:

int iData = 123
std::stringstream ss;
ss << 123;

but not this afterwards:

int iDataReadFromStream;
iDataReadFromStream << ss;


ss >> iDataReadFromStream;

Streams always go on the left.

--
Richard Herring
Aug 9 '05 #4
On Tue, 9 Aug 2005 13:48:35 +0000 (UTC), Dylan
<sp******@ontheball.com> wrote:
On Tue, 09 Aug 2005 15:34:25 +0200, Sebastian Hungerecker
<se****@web.de> wrote:
Dylan wrote:
ie I can do this:

int iData = 123
std::stringstream ss;
ss << 123;

but not this afterwards:

int iDataReadFromStream;
iDataReadFromStream << ss;


I'm no expert, but I'd say the latter doesn't work, because it calls the
<<-operator for int and not for stringstream.
Try:
ss>>iDataReadFromStream;


that doesn't work either...


forgive me, it does work.
Aug 9 '05 #5
maybe your thinking of a situation like this...

const int MaxSize = 1023;
std::stringstream convert;
char temp[MaxSize + 1] ={0};
float val;

// Say we have a control that has a "text" floating point value
GetDlgItemText(IDC_SOME_CONTROL, temp, MaxSize);

convert << temp;
convert >> val;

// if you forgot to call this afterward, you would have issues writing or
reading from the stringstream
convert.clear();
convert.str("");

"Dylan" <sp******@ontheball.com> wrote in message
news:lh********************************@4ax.com...
Is there a string stream I can write into and read from?

I've tried std::stringstream but it won't let me read from it.

ie I can do this:

int iData = 123
std::stringstream ss;
ss << 123;

but not this afterwards:

int iDataReadFromStream;
iDataReadFromStream << ss;
Is there a data structure that allows me to do both?

thanks

Aug 9 '05 #6

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

Similar topics

3
by: Michael Weir | last post by:
I'm sure this is a very simple thing to do, once you know how to do it, but I am having no fun at all trying to write utf-8 strings to a unicode file. Does anyone have a couple of lines of code...
0
by: Eugene | last post by:
I'm working on a program which needs to convert a string to various data types. I created a function using string streams and templates to do just that: template<typename T> bool...
5
by: Steve | last post by:
Hi, How can I convert a C++ string to an integer and then an integer back to a string? Is there built-in support for this? Thanks, Steve
5
by: ferran | last post by:
Hi, I'm trying to convert a string to a long double using streams but for some reasing seems to give the wrong values, the idea is to do a precise textual conversion without roundings or...
3
by: Tron Thomas | last post by:
What does binary mode for an ofstream object do anyway? Despite which mode the stream uses, operator << writes numeric value as their ASCII representation. I read on the Internet that it is...
4
by: rainmaker1234 | last post by:
Its very simple in VC++. In the followeing code I have declared a String, and a double than I am taking the string and converting it into Double. getch() at the end is only to pause the screen so...
1
by: Chris | last post by:
I'm reading up on streams and I have two articles that seem to conflict with each other. One article describes streams and lists a few of the major ones (FileStream, Memory Stream, Network...
25
by: electrixnow | last post by:
in MS VC++ Express I need to know how to get from one comma delimited text string to many strings. from this: main_string = "onE,Two,Three , fouR,five, six " to these: string1 =...
28
by: v4vijayakumar | last post by:
#include <string> #include <iostream> using namespace std; int main() { string str; str.resize(5); str = 't';
23
by: KIRAN | last post by:
Hi all, can i split a C string like this? char * p = "Hello \ World\n\r"; is this according to standard? Any help or link to standard regarding the above doubt is aprreciated... Regards, Kiran
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...
0
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 ...

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.