This is the mail archive of the
mailing list for the GCC project.
Re: Where is String class?
- To: oliva at dcc dot unicamp dot br (Alexandre Oliva)
- Subject: Re: Where is String class?
- From: Joe Buck <jbuck at Synopsys dot COM>
- Date: Wed, 7 Apr 99 9:22:46 PDT
- Cc: ildar at faki-campus dot mipt dot ru, egcs at egcs dot cygnus dot com
> On Apr 7, 1999, Ildar Mulyukov <firstname.lastname@example.org> wrote:
> > substitute MFC's CString class. As I can see "string" class from
> > std/bastring.h has less functionality then I need.
> I don't know what you get get with MFC's CString, but `string' is
> Standard C++, likely to work with any C++ compiler, so it's probably
> the way to go.
I occasionally must deal with MFC stuff.
The only things MFC's CString provides that string does not are:
- trimming of whitespace
- case conversion
The first two are trivial to do yourself; the third lets you do
sprintf-style conversion without risk of overflow and is nice to
have. Is that what you need? It could be written as a non-member
void sprintf(string& buffer, const char* format, ...);
Our real problem is that we don't have stringstream in libstdc++ 2.
CString suffers from a common programming error that results in
poor performance. Consider the following code:
CString n_copies_of(const CString& foo, unsigned n)
for (unsigned i = 0; i < n; i++)
tmp += foo;
This function is O(n^2), not O(n). The reason is that each +=
causes a reallocation and copy of the existing string. Microsoft
applications are full of this kind of thing (quadratic performance
on tasks that can be done in linear time) -- on the other hand,
we should be thankful, as it's created such a big market for high-end
ix86 hardware. :-)
If you replace CString with string in the above function, the
performance is O(n).