C++ 该系统找不到指定的文件。在 Visual Studio 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17946772/
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
The system cannot find the file specified. in Visual Studio
提问by Mr. Supasheva
I keep getting this error with these lines of code:
这些代码行我不断收到此错误:
include <iostream>
int main()
{
cout << "Hello World" >>;
system("pause");
return 0;
}
"The system cannot find the file specified"
“该系统找不到指定的文件”
采纳答案by Mike Vine
The system cannot find the file specified usually means the build failed (which it will for your code as you're missing a #
infront of include
, you have a stray >>
at the end of your cout
line and you need std::
infront of cout) but you have the 'run anyway' option checked which means it runs an executable that doesn't exist. Hit F7 to just do a build and make sure it says '0 errors' before you try running it.
该系统找不到指定的文件通常意味着构建失败(它会为你的代码,你缺少#
的盈方include
,你有一个流浪>>
在你结束cout
线,你需要std::
盈COUT),但你有'无论如何运行'选项已选中,这意味着它运行一个不存在的可执行文件。在尝试运行之前,按 F7 进行构建并确保它显示“0 错误”。
Code which builds and runs:
构建和运行的代码:
#include <iostream>
int main()
{
std::cout << "Hello World";
system("pause");
return 0;
}
回答by Rak
The code should be :
代码应该是:
#include <iostream>
using namespace std;
int main() {
cout << "Hello World";
return 0;
}
Or maybe :
或者可能 :
#include <iostream>
int main() {
std::cout << "Hello World";
return 0;
}
Just a quick note: I have deleted the system command, because I heard it's not a good practice to use it. (but of course, you can add it for this kind of program)
只是一个简短的说明:我已经删除了系统命令,因为我听说使用它不是一个好习惯。(但当然,您可以为此类程序添加它)
回答by hani89
I had a same problem and this fixed it:
我有同样的问题,这解决了它:
You should add:
你应该添加:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64
for 64 bit system
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64
对于 64 位系统
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib
for 32 bit system
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib
对于 32 位系统
in Property Manager
>Linker
>General
>Additional Library Directories
在Property Manager
> Linker
> General
>Additional Library Directories
回答by Aaron Thomas
Another take on this that hasn't been mentioned here is that, when in debug, the project may build, but it won't run, giving the error message displayed in the question.
此处未提及的另一个问题是,在调试时,项目可能会构建,但不会运行,并给出问题中显示的错误消息。
If this is the case, another option to look at is the output file versus the target file. These should match.
如果是这种情况,另一个要查看的选项是输出文件与目标文件。这些应该匹配。
A quick way to check the output file is to go to the project's property pages, then go to Configuration Properties -> Linker -> General (In VS 2013 - exact path may vary depending on IDE version).
检查输出文件的一种快速方法是转到项目的属性页,然后转到配置属性 -> 链接器 -> 常规(在 VS 2013 中 - 确切路径可能因 IDE 版本而异)。
There is an "Output File" setting. If it is not $(OutDir)$(TargetName)$(TargetExt)
, then you may run into issues.
有一个“输出文件”设置。如果不是$(OutDir)$(TargetName)$(TargetExt)
,那么您可能会遇到问题。
This is also discussed in more detail here.
这也在此处进行了更详细的讨论。
回答by Mr. Supasheva
Oh my days!!
哦,我的日子!!
Feel so embarrassed but it is my first day on the C++.
感觉很尴尬,但这是我在 C++ 上的第一天。
I was getting the error because of two things.
由于两件事,我收到了错误。
I opened an empty project
I didn't add #include "stdafx.h"
我打开了一个空项目
我没有添加 #include "stdafx.h"
It ran successfully on the win 32 console.
它在 win 32 控制台上成功运行。
回答by anushang
This is because you have not compiled it. Click 'Project > compile'. Then, either click 'start debugging', or 'start without debugging'.
这是因为你没有编译它。单击“项目>编译”。然后,单击“开始调试”或“不进行调试就开始”。