I want to extract a series of elements from the beginning of a char array and put them in a string. The range may be less than or equal to the number of elements.
Here is what I came up with.
// buffer is a std::array<char, 128> std::string message; for (int i = 0; i < numberToExtract; ++i) { message += buffer.at(i); }
Is there a better way to do this?
I was looking at something like a std :: string iterator constructor. For example. std::string(buffer.begin(), buffer.end()) , but I do not need all the elements.
Thanks.
c ++ string arrays c ++ 11 stdarray
ksl
source share