你如何在C ++中使用'system'命令?

时间:2014-02-02 20:17:30

标签: c++ console game-loop

我正在探索C ++并尝试制作一个清晰屏幕的简单循环。我在C中知道'系统'命令语法:

系统( “CLS”);

将使命令终端清除屏幕。这是代码:

#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;
}    

这是我的错误消息:

error: 'system' was not declared in this scope

我是否需要包含一个库才能在C ++中使用系统?我在书的索引中找不到'system',所以这可能不是C ++完成此任务的合适语法。

1 个答案:

答案 0 :(得分:2)

can be found easily system函数在<cstdlib>标题中定义。另请注意,使用此函数不是一种好的编程习惯。

相关问题