看了你的代码,好像达不到目的。提供以下作参考——
//#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;
}