问题
I have a problem with understanding how to setup VS Code to create C++ (11) programs. I had installed previously VS 2015 community, so I had everything necessary to create a program in one package. Now I want to learn how to do the same thing in text editor/not full IDE.
I have installed c++ extension, created new folder and created simple main.cpp with hello world. 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. I also don't know how to set up json files to compile and debug program in Code. Official documentation doesn't tell me much, and I do not know how to use tools like 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. I guess python automated all necessary actions.
How can do all of that for c++?
回答1:
VSCode is just a code editor, you have to do the compiling by yourself. Python runs on an interpreter, so you don't have to compile the program. For VSCode you have to save the file and then use a compiler to compile the files into an executable. A compile will usually compile the .cpp files into machine code(assembly), which then gets turned into an executable by the linker.
Open terminal/command prompt, or VSCode->View->Integrated terminal. If you don't have a compiler, then I would suggest downloading GCC, because it's fairly easy to use. On Windows you can download it with 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>
来源:https://stackoverflow.com/questions/44377981/vs-code-setup-for-c