字符串数组输入空格,看cin>>s与get(s)区别
举个栗子
#include<iostream>
using namespace std;
int main()
{
char a[100];
char b[100];
cout<<"输入字符串数组:";
cout<<endl;
cin>>a;
gets(b);
cout<<endl;
cout<<"输出:"<<endl;
cout<<"字符串数组a: "<<a<<endl;
cout<<"字符串数组b: "<<b<<endl;
return 0;
}
看一下效果:
或者用cin.getline(s,100);也可以输入空格;
上代码:
#include<iostream>
using namespace std;
int main()
{
char s[100];
cout<<"输入字符串数组:"<<endl;
cin.getline(s,100);
cout<<endl;
cout<<"输出字符串数组: "<<endl<<s;
return 0;
}
看是不是与gets(s)一样。