Sleep(3000); 是等待3秒。(需要再顶部添加#include <windows.h>)
- #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
- int main()
- {
- printf("Cyuyan! ");
- Sleep(3000);
- return 0;
- }
复制代码
system("pause");就是暂停直到你输入任意一个字符结束- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- printf("Cyuyan! ");
- system("pause");
- return 0;
- }
复制代码
getchar();getchar();
本质上等待读入两个字符,也可以起到暂停的作用,但是别人本质上不是用来暂停程序的。这里做了一个假象,等待读入字符。
那为什么一个getchar();不行呢。其实也不是都不行。如果程序没有屏幕输入的话,一个getchar();也可以。但是往往程序都有输入。而我们在输入的时候通常需要敲一个回车来接受输入,第一个getchar();就把回车个读掉了,因此需要第二getchar();来假装还需要读入一个字符,来起到暂停的效果。
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- printf("Cyuyan! ");
- getchar();getchar();
- return 0;
- }
复制代码
|