dude_1967
December 20th, 2002, 09:03 AM
Hello,
How can output to iostreams (example std::cout) be wrapped around and appear on the same line?
In particular, I would like to print some ticker sequence like
Number: 0.0
Number: 0.1
Number: 0.2
all on one line such that the "Number: " part remains steady and the decimal ticker part counts up. I guess the ideal solution would only print the "Number: " part once and cleverly back up over the decimal ticker part. I tried some stuff with '\r', but didn't like the lack of elegance of the implementation. In addition, with '\r' if the results of previous outputs were longer than the present outputs, then the characters will not be erased and they remain as ghost images.
The sample code prints a separate line for each ticker. Can anyone modify the sample code accordingly for the desired ticker effect. I would really appreciate any help.
Thanks a lot.
Chris.
:)
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
std::cout << endl;
for(volatile int n = 0; n <= 100; n++)
{
std::cout << "Number: "
<< double(n) / 10
<< endl;
}
return n;
}
How can output to iostreams (example std::cout) be wrapped around and appear on the same line?
In particular, I would like to print some ticker sequence like
Number: 0.0
Number: 0.1
Number: 0.2
all on one line such that the "Number: " part remains steady and the decimal ticker part counts up. I guess the ideal solution would only print the "Number: " part once and cleverly back up over the decimal ticker part. I tried some stuff with '\r', but didn't like the lack of elegance of the implementation. In addition, with '\r' if the results of previous outputs were longer than the present outputs, then the characters will not be erased and they remain as ghost images.
The sample code prints a separate line for each ticker. Can anyone modify the sample code accordingly for the desired ticker effect. I would really appreciate any help.
Thanks a lot.
Chris.
:)
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
std::cout << endl;
for(volatile int n = 0; n <= 100; n++)
{
std::cout << "Number: "
<< double(n) / 10
<< endl;
}
return n;
}