E23*_*235 3 c++ visual-studio visual-studio-code
我在C++中有简单的控制台应用程序,我成功使用Visual Studio进行编译.
我想尝试Visual Studio Code,所以我将目录复制到安装了Visual Studio Code的计算机上.
我安装了C++扩展:
我在开始时设置了断点并按下F5并收到错误:
启动:程序'输入程序名称,例如c:\ Users\student1\Desktop\ConsoleApp\a.exe'不存在.
当然程序不存在,我正在编译它以使代码成为程序.
我按照说明操作,然后去了launch.json文件:
我将"program"值更改为: "${workspaceRoot}/a.exe"而不是"enter program name, for example ${workspaceRoot}/a.exe".
但同样的问题仍然存在.
任何的想法 ?
Man*_*ddy 11
花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)
小智 4
这个问题主要是由于文件名引起的,如下表所示,Windows 文件夹中的二进制文件名称将是audioMatrixBin而不是audioMatrixBin.exe,但我们必须在这里提到 filename.exe 。
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "audioMatrixBin.exe",
"args": ["AudioMxrMgr4Subaru.conf"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true
}
]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13776 次 |
| 最近记录: |