Welcome

首页 / 软件开发 / C++ / C与C++中标准输入实现方式上的区别

C与C++中标准输入实现方式上的区别2007-10-08刚开始学时遇到一个问题,如下代码:

#include
int main()
...{
char a,b;
printf("Please input the first character:");
scanf("%c", &a);
printf("Please input the second character:");
scanf("%c", &b);
printf("The two characters are %c, %c", a, b);
return 0;
}
程序运行结果如下:

而下面这段程序却可以正常运行:

#include
int main()
...{
char a;
int b;
printf("Please input the first character:");
scanf("%c", &a);
printf("Please input the second integer:");
scanf("%d", &b);
printf("The two characters are %c, %d", a, b);
return 0;
}
运行结果如下: