System("clear") error

Thread Tools Search this Thread
Top Forums Programming System("clear") error
# 1  
Old 12-04-2013
System("clear") error

I was trying to run a connect four game in C++, but I got this error while compiling in Cygwin:

c4.cpp: In member function ‘void connectFour::clearScreen()’:
c4.cpp:162:35: error: ‘system’ was not declared in this scope

The coder left this above the part using "system("clear")":

//Set for OSX currently - Change the inner system call for Windows or Linux

How can I solve this problem?
# 2  
Old 12-04-2013
At the top of the program,
#include <stdlib.h>

That will fix the error. Whether it will work I am less certain. The contents of system() are system-dependent. cygwin might have a clear utility or might not. If this was a Windows commandline program rather than cygwin you'd probably do system("CLS");
# 3  
Old 12-04-2013
Adding to Corona's reply...
I am not sure that clear exists in CygWin.
If it does it will be "clear.exe" inside the "/bin" folder(/drawer/directory)...
You could try this as an alternative:-
#include <cstdlib>

int main()
	system("printf '\033[2J\033[H'");        // This is the important line...
	return 0;

Compiled inside OSX 10.7.5, default bash terminal...


Forgot to add that compiling this under OSX required:-
#include <cstdlib>

Last edited by wisecracker; 12-04-2013 at 05:16 PM..
# 4  
Old 12-04-2013
You do not need system() to print escape codes in C:

printf("\x1b[2J\x1b[H");  fflush(stdout);

This User Gave Thanks to Corona688 For This Post:
# 5  
Old 12-04-2013
Remember! To use the "printf()" function then......
#include <stdio.h>


#include <cstdio>

......will be needed...
Or else this error will result:-
AMIGA:barrywalker~> g++ clear.cpp
clear.cpp: In function ‘int main()':
clear.cpp:8: error: ‘printf' was not declared in this scope
AMIGA:barrywalker~> _

This User Gave Thanks to wisecracker For This Post:
# 6  
Old 12-06-2013
When you call system("some_command") -
You are invoking a new process, and the new process may not be running the same shell you connected with. In cygwin that shell is: /bin/sh, which is bash. The other point is it may not be able to find command executables like /bin/clear unless you add the full file name.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

What does "force devmap reload" as in "multipath -r" means for my system and stability of my system?

Cannot present unpresented disks back again. On a test server tried this as a solution "multipath -r" and it worked. Too worried to try it in production before I know all the information. Any info would be appreciated! Also some links to the documentation on this specific issue could help a... (1 Reply)
Discussion started by: jsteppe
1 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Shell Programming and Scripting

awk "date" and "system" command

Hello experts! I need your help please I have a file.txt of which I want to extract 3rd and 4th columns with date with the form e.g.: 2016-11-25 03:14:50and pass them to "date" command, but also append the 9th column in a file as well. So I want to execute date -d '2016-11-25 03:14:50' ... (2 Replies)
Discussion started by: phaethon
2 Replies

4. UNIX for Dummies Questions & Answers

[Solved] How to clear "history" command entries??

As in the title, how to clear the history entries? For eg: if i enter history, series of linux commands getting displayed from day 1. I need to clear those entries and want linux commands to be stored freshly. Thanks in advance (6 Replies)
Discussion started by: karthick nath
6 Replies

5. UNIX for Dummies Questions & Answers

Unix "look" Command "File too large" Error Message

I am trying to find lines in a text file larger than 3 Gb that start with a given string. My command looks like this: $ look "string" "/home/patrick/filename.txt" However, this gives me the following message: "look: /home/patrick/filename.txt: File too large" So, I have two... (14 Replies)
Discussion started by: shishong
14 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Filesystems, Disks and Memory

Error:"File system full"

Hi, I'm getting an error with my filesystems. After /dev/dsk/c0t0d0s7.......................100%............/export/home and #ls -l drwxr----.......................512......TT_DB drw..............................8192.....lost+found (10 Replies)
Discussion started by: bacanaks
10 Replies

8. HP-UX

ERROR: more than one instance of overloaded function "vprintf" has "C" linkage

Hi people! I've got this own library: -------------------------------------------- Personal.h -------------------------------------------- #ifdef __cplusplus extern "C" { #endif #include <stdio.h> #include <stdarg.h> #include <string.h> ... (0 Replies)
Discussion started by: donatoll
0 Replies

9. UNIX for Dummies Questions & Answers

"@" will clear the current line in terminal

I just found that the current command line will be cleared when trying to input the "@" sign to the terminal. I checked current alias, but found nothing. Would you please provide some suggestion about it? (4 Replies)
Discussion started by: sleepy_11
4 Replies

10. AIX

"Web-based System Manager" error

Hi, I have a problem with the "Web-based System Manager" on AIX 5.3 ML04. When selecting category "File Systems" and the "Overview and Tasks", I get a popup with the following error: : The remote call failed; nested exception is:... (1 Reply)
Discussion started by: Ebbi
1 Replies
Login or Register to Ask a Question