C++ 清除字符串所有空格

// 清空字符串所有空格
std::string& ClearAllSpace(std::string &str)
{
    int index = 0;
    if (!str.empty())
    {
        while ((index = str.find(' ', index)) != std::string::npos)
        {
            str.erase(index, 1);
        }
    }
    return str;
}

 

posted on 2021-08-26 15:42  缘随风烬  阅读(1342)  评论(0编辑  收藏  举报