This is the mail archive of the
mailing list for the GCC project.
Re: Where is String class?
- To: Joe Buck <jbuck at Synopsys dot COM>
- Subject: Re: Where is String class?
- From: Ildar Mulyukov <ildar at faki-campus dot mipt dot ru>
- Date: Fri, 23 Apr 1999 16:11:32 +0400 (EEST)
- cc: egcs at egcs dot cygnus dot com
Another thing that MFC CString provides is direct access to its buffer.
Ildar Mulyukov, student of DACR, MIPT (Moscow, Russia)
e-mail: email@example.com, ICQ# 4334029
On Wed, 7 Apr 1999, Joe Buck wrote:
> > 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
> - CString::Format
> 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
> function, e.g.
> 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)
> CString tmp;
> for (unsigned i = 0; i < n; i++)
> tmp += foo;
> return tmp;
> 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).