c++输入字符串,去除其中标点及中文,数字等非英文字符,保留空格,英文换行符

2025-04-23 21:13:34
推荐回答(1个)
回答1:

看了你的代码,好像达不到目的。提供以下作参考——

//#include "stdafx.h"//vc++6.0加上这一行.
#include 
#include 
using namespace std;
int main(void){
    string s;
cout << "Input a string...\n";
char c;
while(c=cin.get()){
if(c>='a' && c<='z' || c>='A' && c<='Z' || c==' ' || c=='\n')
s+=c;
if(c=='\n')
break;
}
cout << s << endl;
    return 0;
}