public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Strings and Integers?
@ 1997-11-30  6:03 Orn E. Hansen
  1997-11-30 14:29 ` Alexandre Oliva
  0 siblings, 1 reply; 4+ messages in thread
From: Orn E. Hansen @ 1997-11-30  6:03 UTC (permalink / raw)
  To: egcs

Hi,

  I just downloaded your egcs-1127 and compiled it.  But when trying
to use it with some programs I have, I noticed that there is no
implementation of String class.  There is only a 'string' class, which 
appears to be unuseable? i.e.

#include <iostream.h>
#include <string.h>

main()
{
  string str;

  cin >> str;
  cout << "Containts: {" << str.data() << "}" << endl;
}

  reveals the error, that "class string" is undefined...

  Are any of these classes available, or planned ?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Strings and Integers?
  1997-11-30  6:03 Strings and Integers? Orn E. Hansen
@ 1997-11-30 14:29 ` Alexandre Oliva
  1997-12-01  3:36   ` Orn E. Hansen
  0 siblings, 1 reply; 4+ messages in thread
From: Alexandre Oliva @ 1997-11-30 14:29 UTC (permalink / raw)
  To: Orn E. Hansen; +Cc: egcs

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 <string>, not <string.h>, that is a C header-file.

There's no equivalent of libg++'s class Integer in the C++ standard
library.

-- 
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Strings and Integers?
  1997-11-30 14:29 ` Alexandre Oliva
@ 1997-12-01  3:36   ` Orn E. Hansen
  1997-12-01  5:31     ` David McWherter
  0 siblings, 1 reply; 4+ messages in thread
From: Orn E. Hansen @ 1997-12-01  3:36 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: Orn E. Hansen, egcs

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 <string>, not <string.h>, 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 <string> 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 <iostream.h>
#include <string>
#include <list.h>

extern "C" {

#include <stdlib.h>
#include <locale.h>

           };

main()
{
  list<string> lstr;
  list<string>::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;
  };
}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Strings and Integers?
  1997-12-01  3:36   ` Orn E. Hansen
@ 1997-12-01  5:31     ` David McWherter
  0 siblings, 0 replies; 4+ messages in thread
From: David McWherter @ 1997-12-01  5:31 UTC (permalink / raw)
  To: Orn E. Hansen; +Cc: Alexandre Oliva, egcs

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 <string>, not <string.h>, 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 <string> 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 <iostream.h>
> #include <string>
> #include <list.h>
> 
> extern "C" {
> 
> #include <stdlib.h>
> #include <locale.h>
> 
>            };
> 
> main()
> {
>   list<string> lstr;
>   list<string>::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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1997-12-01  5:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-11-30  6:03 Strings and Integers? Orn E. Hansen
1997-11-30 14:29 ` Alexandre Oliva
1997-12-01  3:36   ` Orn E. Hansen
1997-12-01  5:31     ` David McWherter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).