I just started programming with Xcode in C + + and i have a little problem with the command system ("clear").
When i build and run the program it start but, rather than clear the screen the program writes "TERM environment variable not set" and continues as if nothing had.
So, what can i do for clear the screen ? (what function can i use for clear the screen ?)
1. You should not run external programs with system().
2. Know thine terminal. Microsoft's terminal does not speak the same language as the rest of the world. Some terminals do understand "ANSI codes". Special character sequences that when printed do something else than show up.
Technical: when system() executes 'clear', the clear needs to know the type of terminal and system() did not tell.
Linux# man clear
clear - clear the terminal screen
clear clears your screen if this is possible. It looks in the
environment for the terminal type and then in the terminfo
database to figure out how to clear the screen.
clear ignores any command-line parameters that may be present.
I'd like to add that Xcode's terminal is different than a "normal" terminal, too. If I were you, and you want to really learn C++ (rather than, say Obj-C), I'd get a really good text editor (Sublime Text 3 has a trial that essentially never expires...) and download the developer tools package - which I think comes with Xcode now. Then I'd develop with that editor and compile from the command line (using clang/clang++ if you're using a recent Mac or gcc/g++ on older versions).
I say this because Xcode's terminal is pretty dumb. Don't get me wrong, it's super useful for what it's intended for - logging output. It's just horrible with curses and colors. For example, if you tell a program only to write color codes when the terminal is _able_ to output in color, Xcode's terminal will tell the program it can output colors, but it can't. You get a lot of nasty output on the screen. My 2 cents.