I've been trying to create a basic console progress bar for a program I have (it calculates PI but can take a really long time), what I wanted to know is if there's anyway that I can somehow go to specific line in the console, and manipulate it, like if it looked like this:
1 2 3
44%
|0% 100%|
++++++++++++++++++++++
And what I'd like to do is change the 44% to whatever the current percent is. Is that even possible? And if so, how would I do it?
You don't need multi-threading for this. Your algorithm runs, and in every x-th iteration it changes the console progress bar. Your only problem is to make your program change the console characters in a non-stream based way (no std::cout).
I recommend to use pdcurses or ncurses for portable console manipulation.
if he's making it windows specific there's really no reason why he couldn't/shouldn't use the WinAPI, but I agree that portability through curses is the best course if portability is at all desired.
Thanks for all the replies, just one last question, R0mai, you talked about pdcurses and ncurses, are they c-standard, or will I need to get them somewhere? And how would I implement them so I can #include them.
Oh, and Duoas, the only thing about the code snippet you sent me, how would I set it to the last position that I had before I moved the cursor, like to say, the very last character that was printed out to the console.
CONSOLE_SCREEN_BUFFER_INFO buf;
GetConsoleScreenBufferInfo( STD_OUTPUT_HANDLE, &buf );
COORD oldpos = buf.dwCursorPosition;
// move cursor to new position
// write stuff
// move cursor back to oldpos
I've implimented everything, and it shoots out only one error
1 2
1>\visual studio 2008\projects\picalc\main.cpp(43) : error C2664: 'GetConsoleScreenBufferInfo' : cannot convert parameter 1 from 'DWORD' to 'HANDLE'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Any ideas? I used the exact code that you entered for me, Disch.
just one last question, R0mai, you talked about pdcurses and ncurses, are they c-standard, or will I need to get them somewhere? And how would I implement them so I can #include them.
pdcurses and ncurses, are libraries, you have to download them and follow the installing instructions for your specific platform.
Okay, it sorta worked, it throws no errors when compiling, but when I run it, it says: "Run-Time Check Failure #3 - The variable 'buf' is trying to be used without being initialized"
Here is a snippet of the implementation of the code that you guys have been sending me.
Okay, just added it, don't know how that got deleted, but now it says that it doesn't know the identifier. I've #include <windows.h> Unless it's in another library.