简体   繁体   English

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

[英]How to use Visual Studio C++ Compiler?

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. 我最近安装了Visual Studio 2013.我可以创建一个新项目(Visual C ++),但我必须遇到的错误是我无法运行该应用程序。 Here is the code that I'm trying to run on Visual Studio 2013. 这是我试图在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, 值不能为null,
Parameter name: solutionDirectory. 参数名称:solutionDirectory。

What am I missing here? 我在这里错过了什么?

Here is an image for this: 这是一张图片:

在此输入图像描述

In Visual Studio, you can't just open a .cpp file and expect it to run. 在Visual Studio中,您不能只打开.cpp文件并期望它运行。 You must create a project first, or open the .cpp in some existing project. 您必须首先创建项目,或在某个现有项目中打开.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 . 转到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". 在下一页上,请务必选中“清空项目”。

Then, You can add .cpp files you created outside the Visual Studio by right clicking in the Solution explorer on folder icon "Source" and Add->Existing Item. 然后,您可以通过右键单击文件夹图标“Source”和Add-> Existing Item上的Solution explorer来添加您在Visual Studio外部创建的.cpp文件。

Obviously You can create new .cpp this way too (Add --> New). 显然你也可以用这种方式创建新的.cpp(Add - > New)。 The .cpp file will be created in your project directory. .cpp文件将在项目目录中创建。

Then you can press ctrl+F5 to compile without debugging and can see output on console window. 然后你可以按ctrl + F5编译而无需调试,可以在控制台窗口看到输出。

You may be forgetting something. 你可能会忘记一些事情。 Before #include <iostream> , write #include <stdafx.h> and maybe that will help. #include <iostream>之前,写下#include <stdafx.h> ,也许这会有所帮助。 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." 然后,当您完成编写时,单击测试,然后单击构建中的输出,然后在完成处理/编译时,按Ctrl + F5打开命令提示符,它应该有输出并“按任意键继续”。

应用程序将无法运行,因为您需要将Source1.cpp文件重命名为Main.cpp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM