NOT clearing the screen would solve that particular problem.
But if you are doing screen clearing, then you are using non-portable code [or calling system() - which I think is worse], so you may as well throw in a a "getch" into the mix of non-portable functions. Just make sure that you put it in a special place, so that when you try to do the same thing on a different OS, you can easily replace what the actual function is.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Mhh, its good that i raised this issue then because a friend told me its not good to clear screens, but he didn't explain why. Exactly how do i transfer outputs on new screens? Obviously i can put the entire program on the same screen ... I would like to write portable code, so help me please!!!!
If you want to write portable code, you should probably give up on console apps.
Typically, whatever you do, you cannot clear the screen is a truly portable way. Here's more info anyway:
http://faq.cprogramming.com/cgi-bin/...&id=1043284385
My guess is you are suggestion that i use
over system("cls");, which am happy to do if it means portability .....Code:#include <windows.h> void clear_screen ( void ) { DWORD n; /* Number of characters written */ DWORD size; /* number of visible characters */ COORD coord = {0}; /* Top left screen position */ CONSOLE_SCREEN_BUFFER_INFO csbi; /* Get a handle to the console */ HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE ); GetConsoleScreenBufferInfo ( h, &csbi ); /* Find the number of characters to overwrite */ size = csbi.dwSize.X * csbi.dwSize.Y; /* Overwrite the screen buffer with whitespace */ FillConsoleOutputCharacter ( h, TEXT ( ' ' ), size, coord, &n ); GetConsoleScreenBufferInfo ( h, &csbi ); FillConsoleOutputAttribute ( h, csbi.wAttributes, size, coord, &n ); /* Reset the cursor to the top left position */ SetConsoleCursorPosition ( h, coord ); }
The part that means portability is the abstraction of clearing the screen to a function, in this case one named clear_screen. You could also have written:Originally Posted by csonx_p
To actually be portable, you would need to implement clear_screen() differently as required by each supported platform, and then build the program such that the correct version of clear_screen() is chosen for the given platform.Code:void clear_screen() { system("cls"); }
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
There's no way to do it portable since C/C++ lacks facilities to clear the screen.
Everything you do will be unportable, relying on some platform-specific API.
But that mentioned, the best thing to do is take laserlight's advice. This is typically how big libraries make themselves portable, including Boost I would think.
Downloaded pdcurses, just by including <curses.h>, i get strange compile warnings & errors...
some here ..
etc...Code:warning C4005: 'MOUSE_MOVED' : macro redefinition error C2059: syntax error : '(' error C2039: 'usr_iter' : is not a member of 'std::vector<_Ty>' error C2668: 'std::vector<_Ty>::end' : ambiguous call to overloaded function
anyone????????????
Or is it because i have windows.h included somewhere?
The "macro redefined" usually tells you where it was previously defined [although sometimes you have to look at the raw compiler output rather than the error summary to see that].
Including windows.h should be limited to places where you REALLY have to do that - if nothing else because it is really large and it takes quite some time to compile lots of files that include windows.h.
You probably do not want to include curses.h and windows.h in the same source file - there should be no need to use windows.h in a curses application - if you are calling some windows function that curses doesn't have it's own version of, then you probably want to isolate that, as described previously, in a "windows stuff" source file, and then include a header file like "osindeps.h" that define the OS dependant functions in a OS-independent way [for example, if you need a delay/sleep function, Windows and Linux do different variants here, so you'd put your own os independent function declaration in osindeps.h, and then make the translation in your widnows_stuff.c or linux_stuff.c].
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.