Linux.com

Author Message
Joined: Apr 13, 2008
Posts: 3
Other Topics
Posted Apr 14, 2008 at 6:42:16 PM
Subject: Strange STL behavior

Hi All,

I'm working on an old linux machine, which I don't have root access to. I've updated gcc and binutils to something more modern, gcc 4.1.2, binutils 2.17. glibc is 2.2.2, so pretty old.

I've noticed that istringstream 's don't work properly. Say the istringstream contains a few numbers, "3.5 10.2 72.0" . I can only read in one of the numbers. After the first number is read, the istringstream is invalidated! Anyone know what could be causing this?? I know my g++ is somewhat working, because pair 's work just fine, and they didn't work with the older version of gcc on this machine (2.9.6).

Here's my test program, and the output I see.


#include <string>
#include <iostream>
#include <sstream>

using namespace std;

int main (int argc, char* argv)
{
string A_String;
pair<double,double> A_Pair;

A_String="20.9 33.4";

istringstream A_ISS(A_String,ios::in);

cout << "A_String: " << A_String << endl;
cout << "A_ISS: " << A_ISS << endl;
cout << "A_ISS.str(): " << A_ISS.str() << endl;


A_ISS >> A_Pair.first;

cout << "A_ISS After ReadA: " << A_ISS << endl;
cout << "A_ISS.str() After ReadA: " << A_ISS.str() << endl;

A_ISS >> A_Pair.second;

cout << "A_ISS After ReadB: " << A_ISS << endl;
cout << "A_ISS.str() After ReadB: " << A_ISS.str() << endl;

cout << "A and B: " << A_Pair.first << "\t" << A_Pair.second << endl;

return 0;
}

And the output


A_String: 20.9 33.4
A_ISS: 0xbfffe808
A_ISS.str(): 20.9 33.4
A_ISS After ReadA: 0xbfffe808
A_ISS.str() After ReadA: 20.9 33.4
A_ISS After ReadB: 0
A_ISS.str() After ReadB: 20.9 33.4
A and B: 20.9 0


Any ideas as to what is wrong???

Thanks,
Jeff

Back to top Profile Email Website
jdallen83
Joined Apr 13, 2008
Posts: 3

Other Topics
Posted: Apr 14, 2008 7:11:25 PM
Subject: Strange STL behavior

Follow up,

I believe this is due to something wrong with libc.so.6 . I found a copy of libc-2.2.4 (From GLIBC 2.2.4, rather than 2.2.2) and, using that instead of libc-2.2.2 makes it work! So, now I just need to upgrade to GLIBC 2.2.4 without destroying everything, right?

Thanks

Back to top Profile Email Website
proopnarine

Joined Apr 03, 2008
Posts: 399
Location:San Francisco

Other Topics
Posted: Apr 15, 2008 3:36:24 AM
Subject: Strange STL behavior

That's interesting! I was just about to suggest some sort of pointer problem (not being a big STL string user) when I read your follow-up. Might be worth dropping the gcc folks a note about this.

Take the red pill www.calacademy.org/blogs

Back to top Profile Email Website
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya