哈哈, 讲真的, 你这方法算是投机取巧了, 不删除直接输出不带a的字符串, 刷题应该能过
#include <iostream>
using namespace std;
int main(){
string str;
cout << "please input a character string:" << endl;
getline(cin, str);
cout << "the result after delete 'a' is:" << endl;
for(int i = 0; str[i] != '\0'; i++){
if (str[i] != 'a')
cout << str[i];
}
}
#include<iostream>
using namespace std;
int main(){
char zifu[50];
cout<<"please input a character string:"<<endl;
cin.getline(zifu, 50);
cout<<"the result after delete 'a' is ";
for(int t=0;zifu[t]!='\0';t++){
if(zifu[t]!='a'){
cout<<zifu[t];
}
}
return 0;
}
直接用gets[zifu]可以读入一行也不会影响你的空格输出