c++ 去字符串两边的空格

void trim(string &s) 
    {
        if (s.empty()) 
        {
            return ;
        }
        s.erase(0,s.find_first_not_of(" "));
        s.erase(s.find_last_not_of(" ") + 1);
    }

find_first_not_of()与find_first_of()功能正好相反。不懂得可以先看我写的find_first_of()函数功能详解 find_firat_of()函数是在字符串中查找子串出现过的任意字符,也可以所字符串与子串都有的字符。 find_first_not_of()函数是在字符串中查找子串没有出现过的任意字符,也可以说是,字符串中有而子串中没有的字符

原文地址:https://www.cnblogs.com/wsw-seu/p/14076131.html