读书人

C++里有没有删除字符串中的空格的函数

发布时间: 2012-02-26 20:19:43 作者: rapoo

C++里有没有删除字符串中的空格的函数
C++里有没有删除字符串中的空格的函数?
有的话,是怎么个用法?

[解决办法]
string str = "....... ";
str.erase(remove(str.begin(),str.end(), ' '),str.end());
[解决办法]
#include <map>
#include <string>
#include <cctype>
using namespace std;
int main()
{
string str( "hello world!!! ");
for(string::size_type index=0;index!=str.size();++index)
{
if(isspace(str[index])) //如果str[index]为空白,则为Ture
str.erase(index,1);
}
cout < <str;
}

读书人网 >C++

热点推荐