首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

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

2012-02-26 
C++里有没有删除字符串中的空格的函数C++里有没有删除字符串中的空格的函数?有的话,是怎么个用法?[解决办

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;
}

热点排行