gets 和 cin 在输入字符串时的区别
如果字符串中有空格,那么cin是截至到空格为止,结束输入,gets则是全部接收
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
char s[10000];
char s2[1000];
int main()
{
gets(s);
cin >> s2;
int t = 0;
int len,len2 ;
len = strlen(s);
len2 = strlen(s2);
cout << s << endl;
cout << s2 << endl;
printf("%s\n%s\n", s, s2);
printf("%d\n%d\n", len,len2);
return 0;
}
输入:
asd asd
asd asd
输出:
asd asd
asd asd
asd asd
asd
asd asd
asd
7
3