Topic: String class


Author: mikes@abc.se \e (Mikael St\eldal)
Date: 1996/07/01
Raw View
If you have something stored in a string object, and want to do
strstream on it, how are you supposed to do that?

The only way I've found is a rather ugly way involving const_cast. And
an even worse way of copying to/from a char[].
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1996/07/03
Raw View
mikes@abc.se \e (Mikael St\eldal) writes:

>If you have something stored in a string object, and want to do
>strstream on it, how are you supposed to do that?

You're not; you're supposed to use `istringstream' or `ostringstream'
(which are `string' streams) rather than `istrstream' or `ostrstream'
(which are `char *' streams).

--
Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1996/07/03
Raw View
In article 89v@onyx.indstate.edu, mikes@abc.se \e (Mikael St\eldal) writes:
>If you have something stored in a string object, and want to do
>strstream on it, how are you supposed to do that?
>
>The only way I've found is a rather ugly way involving const_cast. And
>an even worse way of copying to/from a char[].

We are in a transition period regarding strings and streams, and some
things are currently ugly.

The draft standard has stringstreams as a replacement for strstreams,
and that should solve your problem. You can make a stream out of a string
directly. Stringstreams also have nicer properties than strstreams.

Until your C++ implementation supports stringstreams, you have to somehow
make a char array available and create a strstream with it.

---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: lubell@nist.gov (Josh Lubell)
Date: 08 Feb 1995 14:28:43 GMT
Raw View
I have heard that the ANSI C++ language committee has proposed making
String a built-in C++ data type.  Can someone tell me where I can find
the document specifying the proposed String class?  Has anyone
implemented a String class conforming to the ANSI proposal?

I need this information because I am working on the C++ language
binding for a data access interface that will be part of STEP, an
international standard for product data exchange (ISO 10303).  The
data access interface includes funtions for manipulating strings, and I
would like the interface for our string class to match that proposed
by the ANSI C++ language committee.

Thanks for your help.

--Josh
____________________________________________________________________
                                   Josh Lubell | lubell@cme.nist.gov
National Institute of Standards and Technology |
    Manufacturing Systems Integration Division |
                       A127 Metrology Building | Voice:(301)975-3563
                    Gaithersburg, MD 20899 USA | Fax:  (301)869-0917




Author: jason@cygnus.com (Jason Merrill)
Date: Thu, 9 Feb 1995 00:45:19 GMT
Raw View
>>>>> Josh Lubell <lubell@nist.gov> writes:

> I have heard that the ANSI C++ language committee has proposed making
> String a built-in C++ data type.  Can someone tell me where I can find
> the document specifying the proposed String class?  Has anyone
> implemented a String class conforming to the ANSI proposal?

The ANSI C++ string class is still in flux.  My implementation in
libg++ 2.6.2 conforms (at least mostly) to the proposal accepted a few
meetings back, but the specification has changed since that time.  In
particular, it has been changed to interface better with STL.

Jason




Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 9 Feb 1995 05:01:54 GMT
Raw View
jason@cygnus.com (Jason Merrill) writes:

>>>>>> Josh Lubell <lubell@nist.gov> writes:

>> I have heard that the ANSI C++ language committee has proposed making
>> String a built-in C++ data type.  Can someone tell me where I can find
>> the document specifying the proposed String class?  Has anyone
>> implemented a String class conforming to the ANSI proposal?

>The ANSI C++ string class is still in flux.  My implementation in
>libg++ 2.6.2 conforms (at least mostly) to the proposal accepted a few
>meetings back, but the specification has changed since that time.  In
>particular, it has been changed to interface better with STL.

It might be worth clarifying that the string class is just that: a
class in the library. It is not built into the language like int
or double.
--
Steve Clamage, stephen.clamage@eng.sun.com




Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Thu, 9 Feb 1995 17:53:31 GMT
Raw View
In article <3hc7k2$k2t@engnews2.Eng.Sun.COM> clamage@Eng.Sun.COM (Steve Clamage) writes:
>
>It might be worth clarifying that the string class is just that: a
>class in the library. It is not built into the language like int
>or double.

 I beg to differ. Every class defined as part of the library
is every bit as much an intrinsic part of the C++ language
as "int" and "double".

 No class in the Standard Library has to be implemented
as a class. Within the constraints specified in the Standard,
such types must, of course, work like classes.

 For example, on a machine which had hardware complex
number instructions and registers, complex could be
treated just like double: as a built-in type for which optimal
code was generated by the compiler.

 Similarly, a numeric array class might cause
parallel execution of vector operations like addition.
No C++ class can do that -- which is one reason why
such a type is in the Standard Library in the first place.

 Similarly, an implementation of STL does not have
to use any templates. But it has to work as if a template,
and usually the easiest way to do that is to use
an actual template. But that is NOT a requirement.

 On the contrary, a very great deal of care and
effort has been made by the Library Working Group
to ensure that it is _possible_ to implement most
of the Standard Library in C++ as ordinary C++ classes (etc).
(So portable implementations can exist)

--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,
        81A Glebe Point Rd, GLEBE   Mem: SA IT/9/22,SC22/WG21
        NSW 2037, AUSTRALIA     Phone: 61-2-566-2189