input:
12345
12345
gets()不会接收换行符 (相当于cin.getline( ))
#include <iostream>
#include <stdio.h>
using namespace std;
const int maxn=1e4+10;
int main() {
char str1[maxn], str2[maxn];
//cin.getline(str1, maxn);
//cin.getline(str2, maxn);
gets(str1);
gets(str2);
printf("%s\n%s",str1,str2)
}
输出:
12345 |
---|
12345 |
getline()会接收换行符号,所以需要在第二行输入的时候加上getchar()来吸收‘\n’
#include <iostream>
using namespace std;
const int maxn=1e4+10;
int main() {
char str1[maxn], str2[maxn];
getline(cin,str1);
getchar();
getline(cin,str2);
cout<<str1<<endl<<str2;
}
输出:
12345 |
---|
12345 |