[英]I can't run basic C++ program “ Hello World ” in Visual Studio
I'm learning C++ as first programming language and I can't figure out how to run Hello World program.我正在学习 C++ 作为第一种编程语言,但我不知道如何运行 Hello World 程序。 I was googling for solution but I did not find any.
我正在谷歌搜索解决方案,但我没有找到任何解决方案。
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!";
return 0;
}
Unable to start program 'C:\Users/thom/Desktop/C++/Visual/firstproject/Debug/Hello World.exe'.无法启动程序“C:\Users/thom/Desktop/C++/Visual/firstproject/Debug/Hello World.exe”。 The system cannot find the file specified.
该系统找不到指定的文件。
Try Build -> Rebuild Solution, find the executable in the path shown at the output to run it.尝试Build -> Rebuild Solution,在output所示路径中找到可执行文件运行。 You can also try pressing Ctrl+F5 to build and run
您也可以尝试按 Ctrl+F5 构建并运行
If you create a.cpp file in File > New > File > C++ File?如果在 File > New > File > C++ File 中创建 a.cpp 文件?
If so, the path is not included in the project directory, causing the compiler to fail to find the file.如果是这样,则该路径不包含在项目目录中,导致编译器无法找到该文件。
The correct way is to create a cpp file in the project directory under Explorer.As shown below:正确的做法是在Explorer下的工程目录下创建一个cpp文件。如下图:
You can modify the name of the.cpp, and don't modify the default location.您可以修改.cpp 的名称,不要修改默认位置。
Now you can try to build and run the executable.现在您可以尝试构建和运行可执行文件。
I just run your code on VS2019 and it worked.我刚刚在 VS2019 上运行你的代码,它就可以工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.