| | |
system("cls")
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
system() is portable -- the commands it execute are not. There are no portable ways to clear the screen. You might have to do something like this, where each compiler for the target os defines one of the symbols listed in the code below.
C++ Syntax (Toggle Plain Text)
#ifdef _UNIX_ system("clear"); #elif def _WINDOWS_ system("cls"); #elsif def _OTHER_OPERATING_SYSTEM systgem(<put here whatever works>); #endif
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Why do you want to do that?
(In other words, unless you are writing a full-screen text application like an editor or video game, don't do that.)
Otherwise, on Windows, see Example Two
On Unix/Linux/POSIX:
You'll need to link with one of the following (depending on your system):
-lcurses
-lncurses
-lterminfo
If you are writing a CUI application, though, you should just use Curses directly:
PDCurses
Windows, DOS, OS/2, Plan 9, etc
http://pdcurses.sourceforge.net/
NCurses
POSIX systems, Mac OS X, etc
http://www.gnu.org/software/ncurses/
Getting started
http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
http://web.cs.mun.ca/~rod/ncurses/ncurses.html
Hope this helps.
(In other words, unless you are writing a full-screen text application like an editor or video game, don't do that.)
Otherwise, on Windows, see Example Two
On Unix/Linux/POSIX:
C++ Syntax (Toggle Plain Text)
#include <unistd.h> #include <term.h> void clearscreen() { if (!cur_term) { int success; setupterm( NULL, STDOUT_FILENO, &success ); if (success <= 0) return; } putp( tigetstr( "clear" ) ); }
-lcurses
-lncurses
-lterminfo
If you are writing a CUI application, though, you should just use Curses directly:
PDCurses
Windows, DOS, OS/2, Plan 9, etc
http://pdcurses.sourceforge.net/
NCurses
POSIX systems, Mac OS X, etc
http://www.gnu.org/software/ncurses/
Getting started
http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
http://web.cs.mun.ca/~rod/ncurses/ncurses.html
Hope this helps.
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: question on c++ programing
- Next Thread: Variable working incorrectly?
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node output parameter pointer problem program programming project proxy python read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






