From mboxrd@z Thu Jan 1 00:00:00 1970 From: David McWherter To: "Orn E. Hansen" Cc: Alexandre Oliva , egcs@cygnus.com Subject: Re: Strings and Integers? Date: Mon, 01 Dec 1997 05:31:00 -0000 Message-id: References: <199712011133.MAA10187@oehansen.pp.se> X-SW-Source: 1997-12/msg00013.html Why don't you use the c_str() member of the string? (Or has that gone away in egcs - I do most of my work with G++ still). It should give you what you want, and I'm fairly certain it's a part of the standard...and I don't think that the data() member has to be null terminated, according to the standard, anyways... -David On Mon, 1 Dec 1997, Orn E. Hansen wrote: > Alexandre Oliva writes: > > Orn E Hansen writes: > > > > > I noticed that there is no implementation of String class. > > > > String is part of libg++, that is not included in egcs. egcs does > > include libstdc++, that provides a definition of class string in the > > header file , not , that is a C header-file. > > > > There's no equivalent of libg++'s class Integer in the C++ standard > > library. > > > > Since we're at it. > > I find close to unusable :-) The reason, is that it appears > implemented as "pascal strings"... an example, running the trailing > program will result in this display: > > Enter? 4000 > Enter? 300 > Enter? 50,35 > Enter? 0 > => 4000,00 (4:4000sr/share/i18() > => 300,00 (3:300) > => 50,35 (5:50,35) > > You'll have to explicidly add '\0' to correct this, in the line... > > str = (*ptr) + '\0'; > > While gnu 'String' is implemented, including the extra '\0', the > absence of it, makes defining your own almost preferrable to using > it. I am assuming that this is a "normal" behaviour? as trying it > on libg++ results in the precise same result... > > > ----- program ---- > > #include > #include > #include > > extern "C" { > > #include > #include > > }; > > main() > { > list lstr; > list::iterator ptr; > string str; > double v; > > setlocale(LC_ALL, ""); > do { > cout << "Enter? "; > cout.flush(); > cin >> str; > v = strtod(str.data(), NULL); > if (v != 0.0) > lstr.push_back(str); > } while (v != 0.0); > for (ptr = lstr.begin();ptr != lstr.end();ptr++) { > str = (*ptr); > v = strtod(str.data(), NULL); > cout.form(" => %8.2f (%d:%s)", v, str.length(), str.data()) << endl; > }; > } > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- David T. McWherter dtm@waterw.com