The following code splits "my string" in a vector<string>
:
std::stringstream ss{"my string"};
std::vector<std::string> vec;
std::string tmp;
while (std::getline(ss, tmp, ' ')) {
vec.push_back(tmp);
}
What I understand is that getline
writes its result into tmp
and then tmp
get pushed into the vector by copying it. But would it be more efficient to do vec.push_back(std::move(tmp))
instead so we avoid the copy?