C++实现类似延时停顿的打字效果

2025-05-29 0 81

能够定位光标位置,改变屏幕设置

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56
#include <iostream>

#include <windows.h>

#include <conio.h>

#include <stdlib.h> //system函数所需头文件

#define stoptimelong 500 //Sleep函数以毫秒为单位,Sleep(500);表示停半秒

using namespace std;

//跳到屏幕指定坐标

void gotoxy(int x,int y)

{ CONSOLE_SCREEN_BUFFER_INFO csbiInfo;

HANDLE hConsoleOut;

hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);

GetConsoleScreenBufferInfo(hConsoleOut,&csbiInfo);

csbiInfo.dwCursorPosition.X = x;

csbiInfo.dwCursorPosition.Y = y;

SetConsoleCursorPosition(hConsoleOut,csbiInfo.dwCursorPosition);

}

int main(void)

{ int x=14, y=5;

gotoxy(x, y);

printf("你好!");

Sleep(stoptimelong);

system("color 10"); //调用控制台颜色管理命令,可以改变屏幕和字体的颜色

printf("欢");

Sleep(stoptimelong);

printf("迎");

Sleep(stoptimelong);

printf("来");

Sleep(stoptimelong);

printf("到");

system("color 19");

Sleep(stoptimelong);

printf("计");

Sleep(stoptimelong);

printf("算");

Sleep(stoptimelong);

printf("机");

system("color 37");

Sleep(stoptimelong);

printf("冒");

Sleep(stoptimelong);

printf("险");

system("color 46");

Sleep(stoptimelong);

printf("世");

Sleep(stoptimelong);

printf("界");

Sleep(stoptimelong);

printf("!");

Sleep(stoptimelong);

cout<<endl;

getch();

return 0;

}

演示图片

C++实现类似延时停顿的打字效果

以上所述就是本文的全部内容了,希望能够对大家学习C++有所帮助。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 C++实现类似延时停顿的打字效果 https://www.kuaiidc.com/107176.html

相关文章

发表评论
暂无评论