Home

Hi

developer28 wrote:

> actually i do something like
>
> const char * temp = str1.c_str();
>
> that converts it to a c type string.
>
> and then when i modify the contents of temp, it also affects str2.

You are not allowed to change the contents through a pointer obtained from
c_str(): "const charT* c_str() const; [...] Requires: The program shall not
alter any of the values stored in the array. [...]" (There is a reason why
c_str() returns a pointer to _const_ char)

Probably your implementation uses copy-on-write and you screw things up;
technically you have undefined behavior anyway.

Markus

previous
next

Re: How to optimise this code?
Re: beginner whitespace question
Re: Why "Welcome Message" I post come get posted as the reply to same post ?
Re: The least used keywords in C++, which do you use?
Re: Order of statements using if
Mam Marzenie
Fundacja Sloneczko
Rodzic Po Ludzku
Pajacyk
Podaruj Zycie