先扔一个链接上来,因为怕忘:

https://blog.csdn.net/stude/article/details/7645056

https://blog.csdn.net/lindorx/article/details/78760610

以下才是代码。

做了一个控制台进度条,并显示百分比。

UPDATE: 添加定向修改字符的备忘。19.3.21  18:20

 #include <iostream>
#include <windows.h>
#include <random>
#include <time.h>
#include <string> #define COLOR_WHITE 0x0F
//#define COLOR_GREEN 0x0A #define PROCESS_SIGN ">"
#define PROCESS_SPEED 6
#define PROCESS_MAX 100
#define PROCESS_RATE 9 //MAX IS 10 static std::mt19937_64 randnum;
static CONSOLE_SCREEN_BUFFER_INFO csbi;
static HANDLE hstdout; int RandNum(int min, int max)
{
if (min < )
{
std::cout << "RandNum Function Parameter Error: The min is wrong number! " << std::endl;
return -;
} if (min >= max)
{
std::cout << "RandNum Function Parameter Error: The min and max are wrong numbers! " << std::endl;
return -;
} uint64_t tmpNum = randnum();
return tmpNum % (max - min) + min;
} int PrintWith_(const char* const str, int count, WORD color = COLOR_WHITE)
{
int ret = ; SetConsoleTextAttribute(hstdout, color);
for (int i = ; i < count; i++)
{
ret += printf(str);
}
SetConsoleTextAttribute(hstdout, COLOR_WHITE); return ret;
} void Backspace(int count)
{
PrintWith_("\b", count);
} bool Init()
{
if (PROCESS_RATE > )
{
return false;
} if (PROCESS_SPEED > PROCESS_MAX)
{
return false;
} hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hstdout, &csbi); randnum.seed(GetCurrentTime()); return true;
} int main()
{
if (!Init())
{
std::cout << "Config Error!" << std::endl; ExitProcess();
return ;
} int percent = ;
int spc = ;
while (percent < )
{
int inc = RandNum(, PROCESS_SPEED);
percent += inc;
if (percent > PROCESS_MAX)
{
inc = percent - PROCESS_MAX;
percent = PROCESS_MAX;
} Backspace(spc); PrintWith_(PROCESS_SIGN, inc, FOREGROUND_INTENSITY); char percentText[];
sprintf_s(percentText, " %d%%%%", percent);
spc = PrintWith_(percentText, , FOREGROUND_GREEN); Sleep(( - PROCESS_RATE) * );
} ////TEST:
//COORD pos = { 34, 10 };
//DWORD dWrited = 0;
//FillConsoleOutputCharacter(hstdout, '*', 5, pos, &dWrited);
//FillConsoleOutputAttribute(hstdout, FOREGROUND_BLUE, 3, pos, &dWrited);
//WriteConsoleOutputCharacter(hstdout, "■", 2, pos, &dWrited); std::cout << std::endl;
system("pause"); CloseHandle(hstdout); return ;
}

最新文章

  1. SSIS 2010 BUG 一例
  2. 框架 Onboard-引导页样式制作库
  3. hadoop运行原理之Job运行(四) JobTracker端心跳机制分析
  4. jQueryEasyUI DateBox的基本使用
  5. PHP GBK UTF8互转
  6. hdu Pie
  7. [ActionScript 3.0] AS3 3D星形贴图
  8. TCP/IP协议原理与应用笔记20:直接交付 和 间接交付
  9. hdoj 2091 空心三角形
  10. Mac上面用来录屏的软件(录制gif图片或者mov)
  11. 入门Android开发
  12. CentOS6.9安装mysql5.7
  13. 【Nginx】下载,请求限速,根据URL参数限速
  14. 前端vue系列-起始篇 vue的基本认知
  15. WDTP注册破解
  16. LeetCode 706 Design HashMap 解题报告
  17. Halcon常用算子01
  18. Css基础笔记(部分)
  19. [转载]必须Mark!最佳HTML5应用开发工具推荐
  20. 校友聊---Sprint计划会议总结

热门文章

  1. WordCount程序与测试
  2. C语法简单测试
  3. Leet Code 3. Longest Substring Without Repeating Characters
  4. linux 清理几天前的日志或文件
  5. websocket的属性readyState
  6. 加#include &lt;mysql.h&gt;,报了很多以下错误
  7. Linux:OpenSUSE系统的安装
  8. key单片机按键抖动
  9. WebStorm 安装及使用
  10. H5介绍与测试设计