string类型 :
#include<string.h>
#include<iostream>
using namespace std;
int main(){
string s;
getline(cin,s);
cout<<s<<endl;
return 0;
}
char 类型:
#include<stdio.h>
using namespace std;
int main(){
char s[50];
scanf("%[^\n]",s);//^\n表示一直读到换行符结束
printf("%s\n",s);
return 0;
}
%[^\n]详解:
http://www.cnblogs.com/dreamgoing/p/3587157.html
#include<stdio.h>
using namespace std;
int main(){
int n;
while((scanf("%*[^0-9]"),1) && scanf("%d",&n) && n!=9999)
//如果读入的是非数字 不存储(跳过) 如果是数字 存入n
printf("%d\n", n);
return 0;
}