|
-
October 14th, 2009, 03:25 PM
#1
cout position
Hi all,
Can anyone help with me positioning the output of std::cout in a console application? Basically I want a loop which outputs a sequence of characters (a single letter for example) in the same position each time, replacing the previous character.
Thanks,
Payne747
-
October 14th, 2009, 03:41 PM
#2
Re: cout position
That would have to be done with OS-specific methods. There's nothing about it in the standard library.
-
October 14th, 2009, 04:05 PM
#3
Re: cout position
Thanks, I figured standard libraries wouldn't allow such things on a stream, however I managed to cheat by simply using the carriage return \r along with std::flush to 'cheat' :P
Code:
char progBar[] = {'|', '/', '-', '\\'};
int progPos = 0;
while (something) {
std::cout << "\r" << progBar[progPos] << std::flush;
progPos++;
if (progPos == 4) {
progPos = 0;
}
}
Ugly, but it seems to work, though it doesn't produce very consistent results depending on the loop conditions (mine happens to be waiting on InternetReadFile() so it's quite delayed at times).
-
October 14th, 2009, 07:21 PM
#4
Re: cout position
If you're programming in Windows you can use SetConsoleCursorPosition to position the cursor before a cout.
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
|