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
|