#include <stdio.h>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
int main(int argc,char *argv[])
{
std::string str(" 123 343 4343 -");
char c =' ';
vector<char>::iterator it;
for(it =str.begin();it!= str.end();)
{
if((*it)==c)
{
it = str.erase(it); //返回一个新的迭代器
}
else
{
++it;
}
}
cout<<"str:"<<str<<endl;
return 0;
}
[C++]_[初级]_[删除字符串中的前后空格]
最新推荐文章于 2025-03-10 14:38:52 发布