C++ 错误 C3861:“系统”:未找到标识符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17511456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 21:14:44  来源:igfitidea点击:

error C3861: 'system': identifier not found

c++visual-studio-2010systemintellisenseidentifier

提问by Sepideh Abadpour

I just started a new win32console application in VS 2010 and set the Additional optionsproperty to precompiled headerin the upcoming wizard.

我刚刚win32在 VS 2010 中启动了一个新的控制台应用程序,并在即将到来的向导中将该Additional options属性设置为precompiled header

Based on one of my previous questionsI decided to use the following main prototype:

基于我之前的一个问题,我决定使用以下主要原型:

int main(int argc,  char* argv[])

I also changed the Character Setproperty of the project to Use Multi-Byte Character Set.

我还将Character Set项目的属性更改为Use Multi-Byte Character Set.

But, the following code:

但是,以下代码:

system("pause");

Will produce these two errors:

会产生这两个错误:

error C3861: 'system': identifier not found  
IntelliSense: identifier "system" is undefined

I had the same experience before and there was no error!
Can anyone suggest me what's wrong?

我以前也有过同样的经历,没有错误!
任何人都可以建议我有什么问题吗?

回答by Cody Gray

In C++, you have to include the appropriate header file that contains the declaration of a function in order to use it, otherwise you'll get a compiler error about the identifier not being found.

在 C++ 中,您必须包含包含函数声明的适当头文件才能使用它,否则您将收到有关未找到标识符的编译器错误。

In the case of the systemfunction, it is defined in the stdlib.hheader file.

system函数的情况下,它是在stdlib.h头文件中定义的。

So, to the top of your code file (or in your precompiled header file), add the line

因此,在代码文件的顶部(或在预编译的头文件中),添加行

#include <stdlib.h>

(You use the angle brackets instead of quotation marks because stdlib.his a header found in a place the build tool has been previously told about; this includes system header directories and other directories your build configuration specifically calls for.)

(您使用尖括号而不是引号,因为这stdlib.h是在构建工具之前已告知的位置找到的标题;这包括系统标题目录和您的构建配置特别需要的其他目录。)

Aside from that, I stronglyrecommend againstusing either the Multi-Byte Character Set (all new Windows applications should support Unicode) or the systemfunction, especiallysystem("pause").

除此之外,我强烈建议不要使用多字节字符集(所有新的 Windows 应用程序都应该支持 Unicode)或system函数, 尤其是system("pause").

回答by CJunk

What worked for me was ensuring that the #include "stdafx.h"was the FIRST INCLUDE in the file. So #include <iostream>would therefore be after this.

对我#include "stdafx.h"有用的是确保是文件中的第一个 INCLUDE。因此#include <iostream>,在此之后。

Doing this solved the issue.

这样做解决了这个问题。