100

pp616 2006-04-10 03:09:29
控制台程序中 怎么修改用cout输入的字符
例如cout输入一个工作进度(1%),怎么动态的修改这个进度的显示?

不太熟悉控制台方面的东西。请大虾指点一二。
...全文
159 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
fangrk 2006-04-10
  • 打赏
  • 举报
回复
#include <iostream>
#include <iomanip>
#include <windows.h>
using namespace std;
int main()
{
cout<<"进度: 0%";
for(int i=1;i<100;++i){
Sleep(1000);
cout<<"\b\b\b"<<setw(2)<<i<<'%';
}
}
逸学堂 2006-04-10
  • 打赏
  • 举报
回复
\b Backspace asi码十进制标示好想是8
~~~~

for(int i = 0; i< 100; ++i)
{
cout << "文件进度: " << "\b" << i << "%";
}
jixingzhong 2006-04-10
  • 打赏
  • 举报
回复
char flag;
int i = 1;

printf("1%");

while((flag = getch())!= 'q') //输入了 q 则退出!
{
if(flag == 'y') //输入 y , 更新显示...
printf("\r%d%",++i);
}
jixingzhong 2006-04-10
  • 打赏
  • 举报
回复
如果情况比较简单,
不用中断也可以 ~
jixingzhong 2006-04-10
  • 打赏
  • 举报
回复
用中断

====
另外,
用 cout 输入???
是cin 还是 cout ??
dch4890164 2006-04-10
  • 打赏
  • 举报
回复
就是覆盖掉原先的数字,之后再重新写
dch4890164 2006-04-10
  • 打赏
  • 举报
回复
Escape Sequence Represents
\a Bell (alert)
\b Backspace
\f Formfeed
\n New line
\r Carriage return
\t Horizontal tab
\v Vertical tab
\' Single quotation mark
\" Double quotation mark
\\ Backslash
\? Literal question mark
\ooo ASCII character in octal notation
\xhhh ASCII character in hexadecimal notation
采用\b这个在msdn上可以查到

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧