   Clearing the terminal screen
  Hi, I'm working on a terminal game for Ubuntu Linux right now in C++, and I want to know how to clear the screen.Now I know that there are system specific commands for this, but they say that they are bad to use.The other solution was to add a bunch of newlines, but I have to align it perfectly with some arbitrary number of newlines and I'm not sure it would work right with every terminal size.So how did people do it in old DOS and unix games?   
  Platform specific code.   ;  You can also use a library like pdcurses.   ;  In old PC games, you clear the screen by setting a portion of memory to zero... there is basically just a block of bytes which are "character mapped". Each has an extended-ascii code in it, plus another byte which does colours; foreground RGB and half-bright, background RGB+hb.The screen is usually 80x25ish. So you can clear the screen by just memset()ing the character array to zero.You can't do this on modern operating systems, because the screen isn't owned by your app, it belongs to the os. You'd need to do a lot of messing about to get access to it.SiCrane is right -- curses is the sensible choice for doing this on modern linux.;  Thanks, I've decided to use the platform specific system("clear") only because this game is just for some casual practice with C++, but why is it so bad to use the system() function? I mean, to port it to windows, cant you just replace clear with cls?   ;Quote:Original post by milan_bThanks, I've decided to use the platform specific system("clear") only because this game is just for some casual practice with C++, but why is it so bad to use the system() function? I mean, to port it to windows, cant you just replace clear with cls?It's already been answered really, You're passing a command to the operating system but even so it may vary per implementation. Libraries provide such interfaces rather than relying on something else to perform it for your application.Using system("cls") and "clear" is a choppy piece of code if you're persuing atleast some standard within C++, It's best to learn how to do it in the language and not just hope the system implementation has something for it.   ;  The answer is that system("clear"); won't be remotely performant. It involves a fork, an invoke (to start a shell) and then a fork and an invoke to launch the clear binary.Clear itself links to five libs. One of them is libncurses...If you're going to invoke another process to this, you could at least just fork and exec /usr/bin/clear, instead of causing bash with its lardy environment to be loaded. {I know system says it starts /bin/sh, but on linux that IS bash.);Getting Started with XNA Game Studio 4.0 just got a whole lot easier! View the full article