std::string c_str()

  • Thread starter Christopher Benson-Manica
  • Start date
C

Christopher Benson-Manica

I would like to know whether calling c_str() for a std::string
repeatedly (with no intervening non-const function on the string)
forces the repopulation of the character array or whether the string
can cache the array. I'm guessing that this is a QOI issue, but I
figured I'd ask anyway.

I realize that I can accomplish the same thing with a const char *
here, but the code looks better without it :)
 
G

Gianni Mariani

Christopher said:
I would like to know whether calling c_str() for a std::string
repeatedly (with no intervening non-const function on the string)
forces the repopulation of the character array or whether the string
can cache the array. I'm guessing that this is a QOI issue, but I
figured I'd ask anyway.

I realize that I can accomplish the same thing with a const char *
here, but the code looks better without it :)

This depends on the implementation of std::string. However, in all
likliness, c_str() returns a pointer to the same array if called
multiple times.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top