[opensuse] Display several times a string at a fixed location in terminal
I know that this is rather a simple question for a C++ programmer, but I don't know a better place to ask, since this topic is more related to the operating system than to the C++ language. I want to display the simulation progress in CLI using something like this: for(int n=0;n<10;n++) { sleep(2); cout << (n/9.0) << "%\n"; } How can I display this using the same line instead of jumping each time at a new line ? (besides "\r") Is there a way to make the cursor disappear while displaying? -- Bogdan -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Cristea Bogdan wrote:
I know that this is rather a simple question for a C++ programmer, but I don't know a better place to ask, since this topic is more related to the operating system than to the C++ language. I want to display the simulation progress in CLI using something like this:
for(int n=0;n<10;n++) { sleep(2); cout << (n/9.0) << "%\n"; }
How can I display this using the same line instead of jumping each time at a new line ? (besides "\r") Is there a way to make the cursor disappear while displaying?
If you are getting \r to perform as expected you are doing better than me keep getting a new line when I use it :-) The only thought I would have is to change the terminal emulation or use curses. I would suggest trying the programming list as you will get the attention of people who write code for the OS. - -- ============================================================================== I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone. Bjarne Stroustrup ============================================================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFGwqynasN0sSnLmgIRAoluAKCljyF2s1r2uCcczHxYtVfBxV//LQCdFjyU z3iK4S/RnaY4fHm+86Htc0U= =RiJp -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hi,
for(int n=0;n<10;n++) { sleep(2); cout << (n/9.0) << "%\n"; }
#include <iostream> using namespace std; int main() { int i = 0; cout<<"\nHello World\n"<<endl; for (i=0;i<10;i++) { cout<<"i is now: "<<i; fflush(0); sleep(2); cout<<"\r"; } cout<<endl; } that should display "i is now: X" is same line every time. Apologies for the C C++ mix. Regards, Soyuz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Aug 14 2007 23:31, Cristea Bogdan wrote:
for(int n=0;n<10;n++) { sleep(2); cout << (n/9.0) << "%\n"; }
How can I display this using the same line instead of jumping each time at a new line ? (besides "\r")
Besides \r, \e[1G can be used, but it's even less readable, not to mention less portable.
Is there a way to make the cursor disappear while displaying?
man console_codes Jan -- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (4)
-
Cristea Bogdan
-
G T Smith
-
Jan Engelhardt
-
Mohammad Bhuyan