我想删除字符串中的空格,但是当我运行我的程序并进入“hello world”时,它没有跟我说话。它崩溃,这表明:为什么我无法删除字符串的空间?
#include <bits/stdc++.h>
using namespace std;
int main()
{
string str;
getline(cin,str);
int space;
while(str.find(' ')>=0) {//something wrong happened in the loop
space = str.find(' ');
str.erase(space,1);
}
cout<<str<<endl;
return 0;
}
我很困惑极了,因为我不知道为什么我的字符串是出于range.So如何解决?提前致谢。
我想知道为什么我的程序崩溃而不是如何删除空间 – fgksgf
'#include':这是一个不 - no ... –
3442
我看,比ks为您提醒。 – fgksgf