Python 中有一个非常有用的函数叫做strip()。 . C++ 中有类似的吗?
最佳答案
我用这个:
#include <string>
#include <cctype>
std::string strip(const std::string &inpt)
{
auto start_it = inpt.begin();
auto end_it = inpt.rbegin();
while (std::isspace(*start_it))
++start_it;
while (std::isspace(*end_it))
++end_it;
return std::string(start_it, end_it.base());
}
关于c++ - C++ 中与 Python 的 strip() 类似的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9358718/