![]() |
#2
wp2319572016-11-01 15:05
|
我在网上查了下应该是换行符在缓冲区的原因。
然后网上有人说,scanf 用空白符结尾时,scanf会跳过空白符去读下一个字符,所以你必须再输入一个数;
可是我不明白用scanf("%d\n",&a);后为什么换行符不会被字符串读取了
http://blog.

#include <iostream>
#include <string>
using namespace std;
int main( )
{
string str1;
string str2;
int a;
scanf_s("%d\n", &a);
getline(cin,str1);
getline(cin, str2);
cout << str1<<endl;
cout << str2 << endl;
scanf_s("%d\n", &a); //这里多了一个回车符\n
if (a % 4 != 0)
printf("the num is no 闰年\n");
else if (a % 100 && a % 400 != 0)
printf("the num is no 闰年\n");
else
printf("the num is 闰年\n");
return 0 ;
}
#include <string>
using namespace std;
int main( )
{
string str1;
string str2;
int a;
scanf_s("%d\n", &a);
getline(cin,str1);
getline(cin, str2);
cout << str1<<endl;
cout << str2 << endl;
scanf_s("%d\n", &a); //这里多了一个回车符\n
if (a % 4 != 0)
printf("the num is no 闰年\n");
else if (a % 100 && a % 400 != 0)
printf("the num is no 闰年\n");
else
printf("the num is 闰年\n");
return 0 ;
}