赞
踩
输入一个0~1的double p,在控制台中当前光标位置开始使用当前字符颜色绘制对应长度的进度条。
void gotoxy(int x,int y) { COORD pos; pos.X=x; pos.Y=y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos); } void drawbar(double p) { int i; if(p>=0.99999999) { for(i=10; i--; i>0)cout<<"█"; return; } int a; CONSOLE_SCREEN_BUFFER_INFO xy; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &xy); for(i=10; i--; i>0)cout<<" "; gotoxy(xy.dwCursorPosition.X,xy.dwCursorPosition.Y); a=(int)(p*10); for(i=a; i--; i>0)cout<<"█"; if(a==10)return; i=(int)((p*10-(int)(p*10))*8); switch(i) { case 0: cout<<" "; break; case 1: cout<<"▏"; break; case 2: cout<<"▎"; break; case 3: cout<<"▍"; break; case 4: cout<<"▌"; break; case 5: cout<<"▋"; break; case 6: cout<<"▊"; break; case 7: cout<<"▉"; break; } for(i=9-a; i--; i>0)cout<<" "; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。