简体   繁体   English

C ++的VS代码设置

[英]VS Code setup for C++

I have a problem with understanding how to setup VS Code to create C++ (11) programs. 我在理解如何设置VS Code以创建C ++(11)程序时遇到问题。 I had installed previously VS 2015 community, so I had everything necessary to create a program in one package. 我之前安装了VS 2015社区,所以我拥有在一个软件包中创建程序的所有必要条件。 Now I want to learn how to do the same thing in text editor/not full IDE. 现在,我想学习如何在文本编辑器/非完整的IDE中执行相同的操作。

I have installed c++ extension, created new folder and created simple main.cpp with hello world. 我已经安装了c ++扩展名,创建了新文件夹并使用hello world创建了简单的main.cpp。 I don't know how to tell VS Code to use Visual C++ Compiler and Debugger, or which other compiler to download an set up. 我不知道如何告诉VS Code使用Visual C ++编译器和调试器,或使用哪个其他编译器下载设置。 I also don't know how to set up json files to compile and debug program in Code. 我也不知道如何设置json文件来编译和调试Code中的程序。 Official documentation doesn't tell me much, and I do not know how to use tools like CMake. 官方文档并没有告诉我太多,而且我也不知道如何使用CMake之类的工具。

I just want to learn to create that manually, setting up Code for python was just a matter of instaling a package an adding path variable then all I had to do was to click debug in with integral console setting. 我只想学习手动创建,为python设置代码只是安装一个软件包并添加路径变量,然后我要做的就是单击带有集成控制台设置的debug。 I guess python automated all necessary actions. 我猜想python自动化了所有必要的动作。

How can do all of that for c++? C ++如何做到所有这些呢?

VSCode is just a code editor, you have to do the compiling by yourself. VSCode只是一个代码编辑器,您必须自己进行编译。 Python runs on an interpreter, so you don't have to compile the program. Python在解释器上运行,因此您无需编译程序。 For VSCode you have to save the file and then use a compiler to compile the files into an executable. 对于VSCode,您必须保存文件,然后使用编译器将文件编译为可执行文件。 A compile will usually compile the .cpp files into machine code(assembly), which then gets turned into an executable by the linker. 编译通常会将.cpp文件编译为机器代码(程序集),然后由链接程序转换为可执行文件。

Open terminal/command prompt, or VSCode->View->Integrated terminal. 打开终端/命令提示符,或者打开VSCode-> View-> Integrated终端。 If you don't have a compiler, then I would suggest downloading GCC, because it's fairly easy to use. 如果您没有编译器,那么我建议您下载GCC,因为它非常易于使用。 On Windows you can download it with Cygwin. 在Windows上,您可以使用Cygwin下载它。 Using the terminal/command prompt you would then compile your files with the compiler of your choice. 然后,使用终端/命令提示符使用您选择的编译器来编译文件。 In GCC it would look like this 在海湾合作委员会,它看起来像这样

g++ <.cpp files> -o <output file>

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

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