如何使用 Visual Studio C++ 编译器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19503515/
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 22:55:06  来源:igfitidea点击:

How to use Visual Studio C++ Compiler?

c++visual-studio-2013

提问by Afzaal Ahmad Zeeshan

I recently installed Visual Studio 2013. I can create a new project (Visual C++), but the error I have to come across is that I cannot run the app. Here is the code that I'm trying to run on Visual Studio 2013.

我最近安装了 Visual Studio 2013。我可以创建一个新项目(Visual C++),但是我遇到的错误是我无法运行该应用程序。这是我尝试在 Visual Studio 2013 上运行的代码。

#include <iostream>
using namespace std;

int main() {
    cout << "Hello World";
    return 0;
}

I am sure this code would run, and will output hello world, but in Visual Studio it gives me issues, saying:

我确信这段代码会运行,并会输出hello world,但在 Visual Studio 中它给了我一些问题,说:

Values cannot be null,
Parameter name: solutionDirectory.

值不能为空,
参数名称:solutionDirectory。

What am I missing here?

我在这里缺少什么?

Here is an image for this:

这是一个图像:

enter image description here

在此处输入图片说明

回答by tomi.lee.jones

In Visual Studio, you can't just open a .cppfile and expect it to run. You must create a project first, or open the .cpp in some existing project.

在 Visual Studio 中,您不能只是打开一个.cpp文件并期望它运行。您必须先创建一个项目,或者在某个现有项目中打开 .cpp。

In your case, there is no project, so there is no project to build.

在您的情况下,没有项目,因此没有要构建的项目

Go to File --> New --> Project --> Visual C++ --> Win32 Console Application. You can uncheck "create a directory for solution". On the next page, be sure to check "Empty project".

File --> New --> Project --> Visual C++ --> Win32 Console Application。您可以取消选中“为解决方案创建目录”。在下一页,一定要勾选“Empty project”。

Then, You can add .cppfiles you created outside the Visual Studio by right clicking in the Solution exploreron folder icon "Source" and Add->Existing Item.

然后,您可以.cpp通过右键单击Solution explorer文件夹图标“源”和“添加”->“现有项目”来添加您在 Visual Studio 之外创建的文件。

Obviously You can create new .cpp this way too (Add --> New). The .cpp file will be created in your project directory.

显然,您也可以通过这种方式创建新的 .cpp(添加 --> 新建)。.cpp 文件将在您的项目目录中创建。

Then you can press ctrl+F5 to compile without debugging and can see output on console window.

然后你可以按 ctrl+F5 编译而不调试,可以在控制台窗口看到输出。

回答by TinyMrCaliber

You may be forgetting something. Before #include <iostream>, write #include <stdafx.h>and maybe that will help. Then, when you are done writing, click test, than click output from build, then when it is done processing/compiling, press Ctrl+F5 to open the Command Prompt and it should have the output and "press any key to continue."

你可能会忘记一些事情。之前#include <iostream>,写#include <stdafx.h>一下,也许这会有所帮助。然后,当您完成编写时,单击测试,然后单击构建的输出,然后在完成处理/编译后,按 Ctrl+F5 打开命令提示符,它应该有输出并“按任意键继续”。