| | |
system("cls")
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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?
Views: 1805 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






