If I use this code:
template <typename Streamable>
/* ... */
std::stringstream ss;
ss << function_yielding_a_Streamable();
auto last_char = ss.str().back();
then (I believe) a copy of the string in ss
's buffer will need to be created, just for me to get the last character, and it will then be destroyed. Can I do something better instead? Perhaps using the seekp()
method?
You could do something like this:
char last_char;
std::stringstream ss;
ss << function_yielding_a_Streamable();
ss.seekg(-1,ios::end);//get to the last character in the buffer
ss>>last_char;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With