Suppose I'm calling a function which will populate a given buffer with some data:
populate_buffer(char *buf, size_t buflen);
I want this filled data to finally end up in std::string
. I have 2 approaches...
Approach 1:
char mybuf[32];
populate_buffer(mybuf, 32);
std::string mystr(mybuf, 32);
Approach 2:
std::string mystr;
mystr.resize(32);
populate_buffer(mystr.data(), 32);
What is more efficient?