控制台应用程序中操作期间的进度条
Progress bar during operation in console application
我开始开发一个加密应用程序,但我似乎大大考虑了如何让它在工作时显示进度条。
任务很简单 lSize 是被加密文件的总大小。
C++
中使用以下循环//********** Open file **********
FILE * inFile = fopen (argv[1], "rb");
fseek(inFile , 0 , SEEK_END);
unsigned long lSize = ftell(inFile);
rewind(inFile);
unsigned char *text = (unsigned char*) malloc (sizeof(unsigned char)*lSize);
fread(text, 1, lSize, inFile);
fclose(inFile);
//*********** Encypt ************
unsigned char aesKey[32] = {
/* Hiding this for now */
};
unsigned char *buf;
aes256_context ctx;
aes256_init(&ctx, aesKey);
for (unsigned long i = 0; i < lSize/16; i++) {
buf = text + (i * 16);
aes256_decrypt_ecb(&ctx, buf);
}
aes256_done(&ctx);
//******************************************************
我想知道如何在 for 循环工作时显示它的进度。
我知道我需要计算到目前为止做了多少,但我不知道该怎么做。
你需要的是
多线程。下面是进度条的一些示例源(来自:http://www.cplusplus.com/reference/future/future/(
#include <iostream> // std::cout
#include <future> // std::async, std::future
#include <chrono> // std::chrono::milliseconds
// a non-optimized way of checking for prime numbers:
bool is_prime (int x) {
for (int i=2; i<x; ++i) if (x%i==0) return false;
return true;
}
int main ()
{
// call function asynchronously:
std::future<bool> fut = std::async (is_prime,444444443);
// do something while waiting for function to set future:
std::cout << "checking, please wait";
std::chrono::milliseconds span (100);
while (fut.wait_for(span)==std::future_status::timeout)
std::cout << '.';
bool x = fut.get(); // retrieve return value
std::cout << "n444444443 " << (x?"is":"is not") << " prime.n";
return 0;
}
相关文章:
- 试图在visual studio上用C++创建一个桌面应用程序
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 在C应用程序中运行C++(带有STL)函数
- 使用VerQueryValue检索应用程序的文件描述
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 使用调试/崩溃报告将应用程序部署到客户端
- C++控制台应用程序阻止退出
- 码头化的C++应用程序是否向后兼容早期的内核版本
- 将应用程序从32位移植到64位时出现问题
- 在 Windows/C++ 上使用多进程应用程序的高精度定时操作
- 按下Arduino按钮后,如何在C#应用程序上执行操作
- 在接收 SIGINT 操作时适当地关闭多线程 c++ 应用程序
- LoadLibrary失败带有错误4250:此操作仅在应用程序容器的上下文中有效
- Boost.Asio:由于线程退出或应用程序请求,I/O 操作已中止
- 将互操作 HwndSource 包装在 c++/cli 中,以用于本机 c++/MFC 应用程序
- 从网络应用程序拆包操作类型的正确方式
- 在正在运行的桌面应用程序上模拟用户操作
- Qt - 如何从应用程序内部初始化某些操作
- 控制台应用程序中操作期间的进度条
- 在旧的MFC/Win32应用程序上使用c++互操作时遇到错误