1. 简单的进度条
简单的进度条(
W
i
n
d
o
w
s
Windows
Windows 系统专用)
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main() {
for(int i=1;i<=50;i++) {
for(int j=1;j<=i;j++) {
cout<<"▉";
}
Sleep(20);
system("cls");
}
return 0;
}
简单的进度条
+
+
+ 自定义时间(秒)(
W
i
n
d
o
w
s
Windows
Windows 系统专用)
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
long double miao;
int main() {
cin>>miao;
miao*=1000;
system("cls");
for(int i=1;i<=50;i++) {
for(int j=1;j<=i;j++) {
cout<<"▉";
}
Sleep(miao);
system("cls");
}
return 0;
}
2. 带时间
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
long double ok,now;
int main() {
ok=0.2*50;
for(int i=1;i<=50;i++) {
for(int j=1;j<=i;j++) {
cout<<"▉";
}
for(int j=1;j<=36;j++) {
cout<<" ";
}
cout<<now;
cout<<" "<<ok;
Sleep(0.2*1000);
now+=0.2;
system("cls");
}
return 0;
}
3. 带百分比
#include<bits/stdc++.h>
using namespace std;
void moveProgressBar(int progress, int total, int barWidth) {
float ratio=static_cast<float>(progress) / total;
int barProgress = static_cast<int>(ratio * barWidth);
cout<<"[ ";
for(int i=0;i<barWidth;i++) {
if(i<barProgress) {
cout<<"=";
}
else if(i==barProgress) {
cout<<">";
}
else {
cout<<" ";
}
}
cout<< " ] "<<static_cast<int>(ratio*100.0)<<"%\r";
cout.flush();
}
int main() {
int total=100;
int barWidth=50;
for(int i=0;i<=total;i++) {
moveProgressBar(i,total,barWidth);
this_thread::sleep_for(chrono::milliseconds(100));
}
cout<<endl;
return 0;
}