Thread: Re: [Dev-C++] read numeric data in C++
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Alfred P. R. <al...@ya...> - 2005-03-10 23:30:03
|
That's interesting. The symptom makes it look like istr or i is only being set once. It's hard to tell without looking at it with a debugger....
Doesn't the clear method actually deallocate the string (not the pointer that is implied in the string object). And is it calling string::clear, ios_base::clear, or both? The actual machine line call label was:_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate. I didn't trace into that function. I'm using Insight BTW, using Mixed view.
Possibly it's not flushing the string buffer buffer, which may be implied in the clear method? I didn't go into any of the routines with the debugger, but at the machine level, the only difference is the commented out line. I didn't look to see if it was in the << or >> of istr, though the problem is in it's functionality somewhere.
Jeremy Hill <jer...@co...> wrote:
<snip>
while (fin >> holder)
{
istr << holder;
istr >> i;
cout << holder << "/" << i << endl;
istr.clear(); //stringstreams suck, you have to do
//this to get it to work properly.
}
};
<snip>
Incidently, anyone want to take a crack at why I have to clear the
string of the stringstream for it to work properly? If I don't, I get
this:
10/10
20/10
30/10
40/10
50/10
60/10
70/10
80/10
90/10
100/10
-- Jeremy
<snip>
Alfred P. Reaud
|
|
From: <Mat...@Ve...> - 2005-03-10 23:43:13
|
For some reason this doesn't seem quite right, guys.
If you are trying to empty a stringstream object so you can fill it wil
new/different stuff just call ss.str("").
If you are trying to sync it up and write it out just call ss.flush().
HTH,
Matt
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...]On Behalf Of Alfred P.
Reaud
Sent: Thursday, March 10, 2005 3:30 PM
To: Dev-Cpp UserList
Subject: Re: [Dev-C++] read numeric data in C++
That's interesting. The symptom makes it look like istr or i is only being
set once. It's hard to tell without looking at it with a debugger....
Doesn't the clear method actually deallocate the string (not the pointer
that is implied in the string object). And is it calling string::clear,
ios_base::clear, or both? The actual machine line call label
was:_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate. I didn't
trace into that function. I'm using Insight BTW, using Mixed view.
Possibly it's not flushing the string buffer buffer, which may be implied in
the clear method? I didn't go into any of the routines with the debugger,
but at the machine level, the only difference is the commented out line. I
didn't look to see if it was in the << or >> of istr, though the problem is
in it's functionality somewhere.
Jeremy Hill <jer...@co...> wrote:
<snip>
while (fin >> holder)
{
istr << holder;
istr >> i;
cout << holder << "/" << i << endl;
istr.clear(); //stringstreams suck, you have to do
//this to get it to work properly.
}
};
<snip>
Incidently, anyone want to take a crack at why I have to clear the
string of the stringstream for it to work properly? If I don't, I get
this:
10/10
20/10
30/10
40/10
50/10
60/10
70/10
80/10
90/10
100/10
-- Jeremy
<snip>
Alfred P. Reaud <mailto:al...@ya...>
<http://www.geocities.com/alreaud/>
___________________________________________________________________
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.
|
|
From: Alfred P. R. <al...@ya...> - 2005-03-11 00:07:41
|
Agreed, though that doesn't explain why the << operator doesn't append as one would expect by the analogous functionality of cout. You don't normally have to use a method call to set a string, you just use the = operator. It could be by implication though, if you can take ss.str("") to be synonymous with ss = "", if ss is a C++ string.
Further, that definitely doesn't explain why modifying the control state flags, as the clear method does, would cause the str("") method to occur. At least I'm not seeing it specifically delineated out in the documentation, and couldn't find it in the <sstream> file. It could be in another template, however, that I haven't looked in.
I'm not saying you're wrong Matthew, what I mean is that it's kind of inscrutable behavior on the part of string streams. Thanks for the lesson folks, I'll make sure to refrain from the <sstream> class whenever possible. ;^)
Mat...@Ve... wrote:
For some reason this doesn't seem quite right, guys.
If you are trying to empty a stringstream object so you can fill it wil new/different stuff just call ss.str("").
If you are trying to sync it up and write it out just call ss.flush().
HTH,
Matt
-----Original Message-----
From: dev...@li... [mailto:dev...@li...]On Behalf Of Alfred P. Reaud
Sent: Thursday, March 10, 2005 3:30 PM
To: Dev-Cpp UserList
Subject: Re: [Dev-C++] read numeric data in C++
That's interesting. The symptom makes it look like istr or i is only being set once. It's hard to tell without looking at it with a debugger....
<snip>
Alfred P. Reaud
|
|
From: <Mat...@Ve...> - 2005-03-10 23:43:58
|
Almost forgot... http://www.cplusplus.com/ref/iostream/stringstream/ <http://www.cplusplus.com/ref/iostream/stringstream/> There's your member functions. HTH, Matt -----Original Message----- From: dev...@li... [mailto:dev...@li...]On Behalf Of Alfred P. Reaud Sent: Thursday, March 10, 2005 3:30 PM To: Dev-Cpp UserList Subject: Re: [Dev-C++] read numeric data in C++ That's interesting. The symptom makes it look like istr or i is only being set once. It's hard to tell without looking at it with a debugger.... Doesn't the clear method actually deallocate the string (not the pointer that is implied in the string object). And is it calling string::clear, ios_base::clear, or both? The actual machine line call label was:_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate. I didn't trace into that function. I'm using Insight BTW, using Mixed view. Possibly it's not flushing the string buffer buffer, which may be implied in the clear method? I didn't go into any of the routines with the debugger, but at the machine level, the only difference is the commented out line. I didn't look to see if it was in the << or >> of istr, though the problem is in it's functionality somewhere. Jeremy Hill <jer...@co...> wrote: <snip> while (fin >> holder) { istr << holder; istr >> i; cout << holder << "/" << i << endl; istr.clear(); //stringstreams suck, you have to do //this to get it to work properly. } }; <snip> Incidently, anyone want to take a crack at why I have to clear the string of the stringstream for it to work properly? If I don't, I get this: 10/10 20/10 30/10 40/10 50/10 60/10 70/10 80/10 90/10 100/10 -- Jeremy <snip> Alfred P. Reaud <mailto:al...@ya...> <http://www.geocities.com/alreaud/> ___________________________________________________________________ The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. |
|
From: <Mat...@Ve...> - 2005-03-11 00:11:48
|
Well, even accounting for the weirdness, they still beat sprintf and
snprintf any day of the week!
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...]On Behalf Of Alfred P.
Reaud
Sent: Thursday, March 10, 2005 4:08 PM
To: Dev-Cpp UserList
Subject: RE: [Dev-C++] read numeric data in C++
Agreed, though that doesn't explain why the << operator doesn't append as
one would expect by the analogous functionality of cout. You don't normally
have to use a method call to set a string, you just use the = operator. It
could be by implication though, if you can take ss.str("") to be synonymous
with ss = "", if ss is a C++ string.
Further, that definitely doesn't explain why modifying the control state
flags, as the <http://www.cplusplus.com/ref/iostream/ios/clear.html> clear
method does, would cause the str("") method to occur. At least I'm not
seeing it specifically delineated out in the documentation, and couldn't
find it in the <sstream> file. It could be in another template, however,
that I haven't looked in.
I'm not saying you're wrong Matthew, what I mean is that it's kind of
inscrutable behavior on the part of string streams. Thanks for the lesson
folks, I'll make sure to refrain from the <sstream> class whenever possible.
;^)
Mat...@Ve... wrote:
For some reason this doesn't seem quite right, guys.
If you are trying to empty a stringstream object so you can fill it wil
new/different stuff just call ss.str("").
If you are trying to sync it up and write it out just call ss.flush().
HTH,
Matt
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...]On Behalf Of Alfred P.
Reaud
Sent: Thursday, March 10, 2005 3:30 PM
To: Dev-Cpp UserList
Subject: Re: [Dev-C++] read numeric data in C++
That's interesting. The symptom makes it look like istr or i is only being
set once. It's hard to tell without looking at it with a debugger....
<snip>
Alfred P. Reaud <mailto:al...@ya...>
<http://www.geocities.com/alreaud/>
___________________________________________________________________
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.
|