0

我有一个用 C++ 编写的非常简单的程序,请在此处查看:

#include <iostream>
using namespace std;
int main()
{
cout<<"Simple message"<<endl;
system("msg * test message");
return 0;
}

当我尝试使用 command: 编译此脚本时g++ 1.cpp -o test.exe,出现错误:

1.cpp: In function 'int main()':
1.cpp:6:29: error: 'system' was not declared in this scope
  system("msg * test message");
                         ^

我检查了代码,但我找不到这个错误的原因,我应该改变编译器还是这个代码有错误?

4

2 回答 2

2

system()stdlib.h(或cstdlib用于 C++)中定义。

#include <cstdlib>
于 2015-11-14T17:18:37.947 回答
0

您需要包含该system函数所在的库头文件。

将此添加到顶部:

#include <stdlib.h>  
于 2015-11-14T17:18:49.637 回答