I found an example about how to use std::getline()
, and this is the code snippet:
std::istringstream input("abc|def|gh");
std::vector<std::array<char, 4>> v;
for (std::array<char, 4> a; input.getline(&a[0], 4, '|'); )
v.push_back(a);
We can find that a
is constructed at the for-loop, and it is passed into push_back
as an argument. Is there a better way to make sure there is no temporary object like a
to avoid overhead?
I have found a member function called emplace_back()
to reduce the use of temporary object, but I am not sure how can I use it in this case, or I should just leave it for compiler optimizations?