I was downloading a compiler (I think it was MinGW but I\'m not sure) on windows 2000 the other day (I\'m generally a Mac user, but it wasn\'t my machine), and the downloade
I'm not sure why you ran into problems, but either \b or \r
can be used to do this, I have used \b
.
#include <iostream>
#include <iomanip>
#include <string>
#include <windows.h>
// This is the only non-portable part of this code.
// Simply pause for a specified number of milliseconds
// For Windows, we just call Sleep. For Linux, you'd
// probably call nanosleep instead (with a suitable
// multiplier, of course). Most other systems (presumably)
// have (at least vaguely) similar capabilities.
void pause(int ms) {
Sleep(ms);
}
static const int width = 40;
void show_percent(int i) {
int dashes = (width * i)/100;
std::cout << '|' << std::left << std::setw(width) << std::string(dashes, '-') << '|' << std::setw(3) << i << "%";
}
int main() {
for (int i=0; i<101; i++) {
show_percent(i);
std::cout << std::string(width+6, '\b');
pause(100);
}
}
According to Wikipedia:
The Win32 console does not support ANSI escape sequences at all. Software can manipulate the console with the ioctl-like Console API interlaced with the text output. Some software internally interprets ANSI escape sequences in text being printing and translates them to these calls [citation needed].
Check out this: http://msdn.microsoft.com/en-us/library/ms682073.aspx
I believe SetConsoleCursorPosition
is what allows you to replace text.