clear screen "TERM environment not set" runtime error

How do you clear the screen with c++? I'm using a mac os x 10.3.9 and writing a program in c++ ... I am currently using the basic system("clear") command but I get an error during runtime:

"TERM environment variable not set."

I'm sure this means that the environment for "TERMINAL" (mac os x's command-line tool) is not set...

how do I set the environment for TERMINAL within my program?

any ideas?

-Master of the Obvious


Here is the code I'm using now:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifdef __cplusplus__
  #include <cstdlib>
#else
  #include <stdlib.h>
#endif
using namespace std;

void clearscreen() {
	system("clear");
}
void clearscreen();
int main() 
{
...
switch (choice) {
			case 1:
				clearscreen();
				cout << "ENTER # OF PLAYERS: ";
				cin >> nPlayers; 
				break;
			case 2:
...
return 0;
}
Last edited on
Your code is not the problem... your OS isn't initializing the $TERM environment variable for your console like it should. You need to ask on a Mac forum... (I think).

That said, don't use system() like that. The correct code to clear the screen is at the bottom of this post: http://www.cplusplus.com/forum/articles/10515/#msg49080

Good luck.
why are you running 10.3.9? we up to 10.7.1. It could your outdated system (probably not) but you should look into a more updated system.
Topic archived. No new replies allowed.