C++ 中的函数与 Python 的 strip() 类似吗?

2023-12-31

Python中有一个非常有用的函数,叫做strip() http://docs.python.org/library/string.html?highlight=strip#string.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());
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

C++ 中的函数与 Python 的 strip() 类似吗? 的相关文章

随机推荐