|
-
December 20th, 2002, 10:03 AM
#1
Simple iostream format question
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.

Code:
#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;
}
You're gonna go blind staring into that box all day.
-
December 20th, 2002, 02:40 PM
#2
dude_1967,
Kinda swamped today so I can't modify your code. But have
you tried using the backspace charactor (\b)? I used it a
long time ago to display a console like program progress
baton using printf.
regards, willchop
-
December 21st, 2002, 08:37 AM
#3
use this
well i think this'll help ya
note: this was originally posted to me by zdf
Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char* argv[])
{
double d = 123.45;
float f = 67.89f;
cout << d << endl // 123.45
<< f << endl; // 67.89
cout << fixed << setprecision(1)
<< d << endl // 123.4
<< f << endl; // 67.8
return 0;
}
It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames
-
December 21st, 2002, 05:53 PM
#4
Solved
Thanks.
Used a combination of '\b' and ::std::setprecision() to accomplish the format.
Chris.
You're gonna go blind staring into that box all day.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|