As a C++ programmer I sometimes need deal with memory buffers using techniques from C. For example:
char buffer[512];
sprintf(buffer, \"Hello %s!\", userName.c_s
buffer
is more terse but if it were a vector
, you'd need to do &buffer[0]
anyway.std::string
. If performance becomes a problem, you'd be able to reduce dynamic allocations by just returning the internal buffer. But the std::string
return interface is way nicer and safer, and performance is your last concern.std::vector
, you should never be doing any raw allocation! If you're putting yourself into a position where you might leak (because it needs to be done explicitly), you're doing it wrong.std::string
, std::stringstream
, std::copy
, etc.