473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

istringstream problem

Why does this code only give Value = "Microsoft":

istringstream is(Dest);
is >Value;

where Value is a string& and Dest a char* holding "Microsoft Sans Serif"

--
Derek
Nov 1 '07 #1
4 1212
DerekBaker wrote:
Why does this code only give Value = "Microsoft":

istringstream is(Dest);
is >Value;

where Value is a string& and Dest a char* holding "Microsoft Sans Serif"
Because ">std::string" is defined to read the next
whitespace-delimited word into the string.
Nov 1 '07 #2
"DerekBaker" <De***@DontBother.comwrote in message
news:fg**********@energise.enta.net...
Why does this code only give Value = "Microsoft":

istringstream is(Dest);
is >Value;

where Value is a string& and Dest a char* holding "Microsoft Sans Serif"
As stated, operator<< for stream and std::string is deliminated by
whitespace. A space, end of line, etc...
If you want the entire line use getline.
std::getline( is, Value );
which is delimited by the end of line.
Nov 1 '07 #3
* Jim Langston:
"DerekBaker" <De***@DontBother.comwrote in message
news:fg**********@energise.enta.net...
>Why does this code only give Value = "Microsoft":

istringstream is(Dest);
is >Value;

where Value is a string& and Dest a char* holding "Microsoft Sans Serif"

As stated, operator<< for stream and std::string is deliminated by
whitespace. A space, end of line, etc...
If you want the entire line use getline.
std::getline( is, Value );
which is delimited by the end of line.

The function the code's in is templated for Value. I guess I'll have to
specialize the function for string.

--
Derek
Nov 1 '07 #4
"DerekBaker" <De***@DontBother.comwrote in message
news:fg**********@energise.enta.net...
>* Jim Langston:
>"DerekBaker" <De***@DontBother.comwrote in message
news:fg**********@energise.enta.net...
>>Why does this code only give Value = "Microsoft":

istringstream is(Dest);
is >Value;

where Value is a string& and Dest a char* holding "Microsoft Sans Serif"

As stated, operator<< for stream and std::string is deliminated by
whitespace. A space, end of line, etc...
If you want the entire line use getline.
std::getline( is, Value );
which is delimited by the end of line.

The function the code's in is templated for Value. I guess I'll have to
specialize the function for string.
Usually an arbitrary value is delimited by whitespace anyway, with some
exceptions.

I've found that for std::string sometimes I need one word, sometimes I need
the entire line, it depends on what I am specifically doing at the moment.
As soon as you specialize for std::string to get the entire line you'll find
that you now only need to get one one word.

Nov 1 '07 #5

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

Similar topics

1
by: Samuele Armondi | last post by:
Hi everyone, Since istringstream objects are not assignable, I'm using the following code to allocate some dynamically. My question is: Is this the correct way of doing it? Am I deleting all the...
8
by: Agent Mulder | last post by:
I try to remove the spaces from a string using an old trick that involves an istringstream object. I expect the while-condition while(istringstream>>string) to evaluate to false once the...
3
by: bml | last post by:
Could you help and answer my questions of istringstream? Thanks a lot! 1. Reuse an "istringstream" istringstream ist; ist.str("This is FIRST test string"); ist.str("This is SECOND test...
7
by: Luther Baker | last post by:
Hi, My question is regarding std::istringstream. I am serializing data to an ostringstream and the resulting buffer turns out just fine. But, when I try the reverse, when the istringstream...
4
by: dinks | last post by:
Hi I'm really new to c++ so please forgive me if this is really basic but im stuck... I am trying to make a data class that uses istringstram and overloaded << and >> operators to input and output...
6
by: JustSomeGuy | last post by:
I am passing an istringstream to a function. I want that function to get a copy of the istringstream and not a refrence to it. ie when the function returns I want the istringstream to be...
8
by: Randy Yates | last post by:
Why does this: string AWord(string& line) { return line; } bool MYOBJECT::MyFunction(string &line) { int day;
6
by: James Aguilar | last post by:
Hello all, I am trying to use an istringstream to do some input off of cin by lines. The following snippet does not work: char buf; cin.getline(buf, 90); istringstream line1(string(buf));
1
by: Adam Parkin | last post by:
Hello all, I'm trying to write a function which given a std::string parses the string by breaking the sentance up by whitespace (\t, ' ', \n) and returns the result as a vector of strings. Here's...
11
by: icanoop | last post by:
I would like to do this MyClass x; istringstream("XXX") >> x; // Works in VC++ but not GCC instead of MyClass x; istringstream iss("XXX"); iss >> x; // Works in both GCC and VC++
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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,...
0
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...
0
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
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,...

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.