ein*_*ica 7 c++ string stringstream seek
如果我使用此代码:
template <typename Streamable>
/* ... */
std::stringstream ss;
ss << function_yielding_a_Streamable();
auto last_char = ss.str().back();
Run Code Online (Sandbox Code Playgroud)
然后(我相信)ss需要创建一个缓冲区中的字符串副本,只为我获取最后一个字符,然后它将被销毁.我可以做一些更好的事情吗?也许使用这种seekp()方法?
你可以这样做:
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;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1618 次 |
| 最近记录: |