does not exist "-6ren"> does not exist "-我在 C++ 中有一个简单的控制台应用程序,我成功地使用 Visual Studio 对其进行了编译。 我想尝试 Visual Studio Code,所以我将目录复制到安装了 Visual Stud-6ren">
gpt4 book ai didi

c++ - 无法编译代码 "launch: program does not exist "

转载 作者:太空狗 更新时间:2023-10-29 19:51:21 29 4
gpt4 key购买 nike

我在 C++ 中有一个简单的控制台应用程序,我成功地使用 Visual Studio 对其进行了编译。

我想尝试 Visual Studio Code,所以我将目录复制到安装了 Visual Studio Code 的计算机上。
我安装了 C++ 扩展:
enter image description here

我在开始处设置了断点,然后按 F5,我收到了一个错误:

launch: program 'enter program name, for example c:\Users\student1\Desktop\ConsoleApp\a.exe' does not exist.

enter image description here

当然这个程序是不存在的,我编译它是为了让代码成为程序。

我按照说明转到了 launch.json 文件:

enter image description here

我将 "program" 值更改为:"${workspaceRoot}/a.exe" 而不是 "enter program name,例如 ${ workspaceRoot}/a.exe”

但同样的问题依然存在。
任何的想法 ?

最佳答案

为此花费了 2 个小时。

理想情况下,VS Code 不应该让初学者感到如此困难

VS Code可以像Idea编辑器一样,一步步自动给出每次安装等提示,让初学者不用那么冗长的程序。

要做的步骤顺序(大部分事情都是一次性的):

      one time:          install a C/C++ complier, add to PATH environment variable          install C/C++ plugin for visual studio code          tell visual studio code where the compiler is and what is the short cut to build and run             these are files under ".vscode" (see below)    every project:          crate a project          build project          run project  

详细:

一次:

Note: Point 'A' below can be skipped if you already have a compiler.A. Install a compiler (if you don't have one already)      Example below, installs MinGW c++ compiler on Windows:      Download from here: https://sourceforge.net/p/mingw-w64/mailman/message/36103143/      1. For windows, I downloaded https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/mingw-w64-v5.0.3.zip      2. unzip mingw-w64-v5.0.3.zip      3. rename unzipped folder to MinGW, Move it to C:\MinGW\      4. verify that you have "C:\MinGW\bin\gcc.exe" director/file, otherwise make necessary change to folder  B. Add your compiler to PATH environment variable    1. Add "C:\MinGW\bin" to PATH > user environment variable      2. verify gcc command works from cmd          restart your cmd          run below command in 'cmd'              where gcc              The output should be: C:\MinGW\bin\gcc.exe  C. Restart your visual studio code      1. install C/C++ plugin, as below:          From Menu               View > Extension          Search & Install below extension              C/C++  

每个项目:

注意:每次都可以复制粘贴.vscode文件夹

A. Create a below "myproj" folder & files, like below in below structure:      C:\myproj\myfile.cpp      C:\myproj\.vscode\      C:\myproj\.vscode\c_cpp_properties.json      C:\myproj\.vscode\launch.json      C:\myproj\.vscode\settings.json      C:\myproj\.vscode\tasks.json  

B.从下面的链接下载并覆盖上面的((5 个文件))

https://github.com/manoharreddyporeddy/my-programming-language-notes/tree/master/vscode-c%2B%2B

C. Restart your visual studio/vs code  D. Open project in vs code & run project:  Drag and drop "myproj" folder into visual studio code    BUILD PROJECT:   press "Ctrl + Shift + B" to build your myfile.exe    RUN PROJECT:     press "Ctrl + F5" to run your myfile.exe  

就是这样,希望对你有所帮助。

更多信息:https://code.visualstudio.com/docs/languages/cpp

可选

更好地格式化 C++

C++ formatting  1. Install Clang:     Download from: http://releases.llvm.org/download.html#5.0.2      I have downloaded for windows         "Pre-Built Binaries:" > Clang for Windows (64-bit) (LLVM-6.0.0-win64.exe)    2. Select Add to PATH while installing.    3. Install vs code plugin "Clang-Format" by xaver, this wraps above exe.    4. Restart visual studio code.    Note:   Issue:    As of June 2018, Clang does not format the newer C++17 syntax correctly.   Solution: If so, move that code to another file/ comment & restart the vs code.  That's all. Now press Alt+Shift+F to format (similar key combination in other OS)

关于c++ - 无法编译代码 "launch: program <program_path> does not exist ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47872250/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com