C++ string去除两端空格

 C++ 中,利用string 类自带方法,去除两端空格。

 1 //C++ 去字符串两边的空格
 2 void delete_space(string &s) 
 3 {
 4     if (s.empty()) 
 5     {
 6         return ;
 7     }
 8     s.erase(0,s.find_first_not_of(" "));
 9     s.erase(s.find_last_not_of(" ") + 1);
10 }

 

posted @ 2022-01-17 19:10  西门吹雪~~~  阅读(1313)  评论(0编辑  收藏  举报