是我还是 c 或 c++ 库中没有标准的修剪函数?有没有任何单一的功能可以作为修剪?如果没有,谁能告诉我为什么 trim 不是标准库的一部分?(我知道修剪正在增强)
我的修剪代码是
std::string trim(const std::string &str)
{
size_t s = str.find_first_not_of(" \n\r\t");
size_t e = str.find_last_not_of (" \n\r\t");
if(( string::npos == s) || ( string::npos == e))
return "";
else
return str.substr(s, e-s+1);
}
测试: cout << trim(" \n\r\r\n \r\n 文本在这里\nwith return \n\r\r\n \r\n "); -edit- 我主要想知道为什么它不在标准库中,BobbyShaftoe 的答案很棒。trim 不是标准 c/c++ 库的一部分吗?