std::string stupid question

U

Unforgiven

Flzw said:
Should I delete a char* I got with string::c_str() ?

Nope. The pointer is owned by the string class, and its lifetime is governed
by it. You should not delete the pointer.
 
M

Mike Wahler

Flzw said:
Should I delete a char* I got with string::c_str() ?

No. There's a simple rule you can use to determine
if/when to use 'delete':

Every call to 'new' should eventually be followed by a
call to 'delete'. Every call to 'new[]' should eventually
be followed by a call to 'delete[]'.

If *you* didn't 'new' it, don't 'delete it'.

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,947
Members
47,498
Latest member
yelene6679

Latest Threads

Top