-1

I'm exploring C++ and trying to make a simple loop that will clear screen. I know in C, the 'system' command syntax:

system("cls");

will make the command terminal clear the screen. Here is the code:

#include <iostream>
using namespace std;

int main()
{
    char choice = 'a';
    while(choice != 'x')
    {
        cout << "What is the variable?" << endl;
        cin >> choice;
        system("cls");
    }

    cout << choice << " is the variable" << endl;

    return 0;
}    

This is my error message:

error: 'system' was not declared in this scope

Do I need to include a library to use system in C++? I cannot find 'system' in the index of my books, so this may not be C++'s appropriate syntax to accomplish this.

olevegard
  • 5,294
  • 1
  • 25
  • 29
  • 1
    http://en.cppreference.com/w/cpp/utility/program/system – chris Feb 02 '14 at 20:20
  • 1
    http://www.cplusplus.com/articles/4z18T05o/ I like this artcle because it shows the few different ways that are able to get the job done. I would personally use the last option created by setting all the characters to space then move the curser to 0,0 – Robert Snyder Feb 02 '14 at 20:22

1 Answers1

2

As can be found easily the system function is defined in the <cstdlib> header. Note also that using this function isn't a good programming practice.

BartoszKP
  • 34,786
  • 15
  • 102
  • 130