C++ 如何在visual studio中编译c++文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19684190/
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
How to compile c++ file in visual studio?
提问by Fiodor
I am new to Visual Studio and I don't know how to compile a .cpp file. I made just a single .cpp file (ctr + n => Visual C++ => C++ file) and I tried to compile it. But in place where normally there's a compile button (like with c#) there is strange 'Attach' button. I don't get what's going on, but I thought, Visual C++ might be some different version of normal C++. If so is that possible to compile normal C++ file in Visual Studio?
我是 Visual Studio 的新手,不知道如何编译 .cpp 文件。我只制作了一个 .cpp 文件(ctr + n => Visual C++ => C++ 文件)并尝试编译它。但是在通常有一个编译按钮的地方(比如 c#)有一个奇怪的“附加”按钮。我不明白发生了什么,但我想,Visual C++ 可能是普通 C++ 的一些不同版本。如果是这样,可以在 Visual Studio 中编译普通的 C++ 文件吗?
回答by Spook
The problem is, Visual Studio don't really know, what to do with your .cpp file. Is it a program? Try the following:
问题是,Visual Studio 并不真正知道如何处理您的 .cpp 文件。它是一个程序吗?请尝试以下操作:
File
|New project
Visual C++
|Win32
|Win32 Project
- Select a name and location for the project
- Next
- Choose
Console application
- Choose
Empty project
- Deselect
Precompiled header
- (optionally) Deselect
SDL checks
- Finish
- Right-click on
Source files
and chooseAdd
|New Item...
- Choose
C++ File
- Choose name for this file
Write the following inside:
#include <stdio.h> int main(int argc, char * argv[]) { printf("Hello, world!\n"); return 0; }
Press F5
File
|New project
Visual C++
|Win32
|Win32 Project
- 为项目选择名称和位置
- 下一个
- 选择
Console application
- 选择
Empty project
- 取消选择
Precompiled header
- (可选)取消选择
SDL checks
- 结束
- 右键单击
Source files
并选择Add
|New Item...
- 选择
C++ File
- 选择此文件的名称
在里面写以下内容:
#include <stdio.h> int main(int argc, char * argv[]) { printf("Hello, world!\n"); return 0; }
按F5
回答by rubenvb
You should, just as you did for C#, create a C++ projectand add your source file to that. Then there will be all the build options you ever dreamed of.
您应该像在 C# 中所做的那样,创建一个 C++项目并将源文件添加到该项目中。然后将有您梦寐以求的所有构建选项。