Re: std::string, C strings and c_str()

From: Alwyn (dt015a1979_at_mac.com.invalid)
Date: 11/02/04


Date: Tue, 02 Nov 2004 12:21:50 +0000

In article <42cd213e.0411011854.3d438e92@posting.google.com>, Tabrez
Iqbal <tabrez19_i@rediffmail.com> wrote:
>
> what does this String class offer over the std::string class other
> than the char * conversion operator?

That's the only thing.

> is the conversion operator worth
> the simplicity that it offers over std::string::c_str() method call?

But std::string's c_str() function returns 'const char *', which would
have been of no use to the OP. This at least automates the allocation
and deallocation of memory. A makeshift solution perhaps, but maybe
also better than nothing in the circumstances.

Alwyn



Relevant Pages

  • Re: Smart char * class...
    ... In your example, even with a char* conversion operator, you're going ... What most likely happens is you invoke undefined behavior ...
    (comp.lang.cpp)
  • Re: Problem with operator*()
    ... >> class CBuffer { ... It declares a conversion operator from a class instance ... to a char* (and frankly, I am puzzled by the reported error messages, I ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Should this compile without cast?
    ... > saw fit to cast to char* though... ... The only thing I can think of is if the char* cast was applied not to ... but to an object that had a conversion operator for char*. ...
    (comp.lang.cpp)