简体   繁体   English

如何在Visual Studio Code中使用g ++编译和运行cpp文件?

[英]How to compile and run cpp file using g++ in Visual Studio Code?

I'm trying to use a task, but could only find how to compile: 我正在尝试使用任务,但只能找到如何编译:

{
    "version": "0.1.0", 
    "command": "g++",
    "args": ["-Wall", "${file}"],
    "showOutput": "always"
}

I'd also like to print input/output to console when the program is running. 我还想在程序运行时将输入/输出打印到控制台。

You might want to have a look at https://code.visualstudio.com/Docs/tasks 您可能想看看https://code.visualstudio.com/Docs/tasks

At the end there is an example how to setup the task system to use gcc. 最后有一个示例,说明如何设置任务系统以使用gcc。 If you have more than a handful files to compile you might want to think about using a make file and call make instead of gcc directly. 如果要编译的文件不只几个,则可能需要考虑使用make文件并直接调用make而不是gcc。

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

相关问题 "如何在安装了 WSL 的 Visual Studio Code 中修复“g++:错误:helloworld.cpp:没有这样的文件或目录”?" - How to fix "g++: error: helloworld.cpp: No such file or directory" in visual Studio Code with WSL installed? 如何用其他目录中的依赖项G ++编译.cpp文件 - How To G++ compile A .cpp File With Dependencies In Another Directory 如何使用gcc / g ++编译多个cpp文件头文件? - How to compile multiple cpp file header file using gcc/g++? 如何使用 Visual Studio 代码编译多 cpp 文件? - How to use visual studio code to compile multi-cpp file? Visual Studio Code:如何为 g++ 编译器添加 arguments? - Visual Studio Code: how to add arguments for g++ compiler? 无法使用 Visual Studio Code 中的 g++ 编译 SFML C++ 代码 - Unable to compile SFML C++ code with g++ from Visual Studio Code 在Sublime 2中使用G ++编译多个* .cpp和* .h文件 - Using G++ to compile multiple *.cpp and *.h files in Sublime 2 使用G++编译多个.cpp和.h文件 - Using G++ to compile multiple .cpp and .h files 如何使用一个g ++命令编译多个不相关的.cpp文件 - How to compile multiple unrelated .cpp files using one g++ command Visual Studio Code g++ 在调试时不能用 c++17 编译 - Visual Studio Code g++ does not compile with c++17 when debugging
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM