X S*_*ish 2 c++ string stdstring
我想知道读取std::string对象中最后一行的最快方法是什么意思是最后一次以最快的方式
出现后的字符串\n?
这可以使用just string::find_last_of和string::substrlike 来完成
std::string get_last_line(const std::string &str)
{
auto position = str.find_last_of('\n');
if (position == std::string::npos)
return str;
else
return str.substr(position + 1);
}
Run Code Online (Sandbox Code Playgroud)
见:例子