以为能打开VScode就可以的我实在是太天真了(。
首先安装几个插件。https://www.w3cschool.cn/visualstudiocode/visualstudiocode-lkpj22za.html
然后创建一个文件夹,在文件中创建新的cpp文件。然后用VScode的打开文件夹打开这个文件夹。 错误方法是:Ctrl-N新建了文件。 此时运行和调试会提示要求在文件夹中进行。每次文件夹的开启和关闭都要在菜单栏的file那里。保存是快捷键Ctrl-s。 每次新建文件的时候记得打上后缀名。运行helloworld。 把helloworld的代码先贴上去,通过安装的插件,可以通过右上角的run来在output有输出,但是此时仍然不能调试。 #include<iostream> #include<cstdio> using namespace std; int main() { cout<<"Hello World"<<endl; getchar(); return 0; } 更改配置文件(launch.json) 直接选择左边侧栏的小虫子,看到设置图标,设置要配置的环境是(gdb)Lanuch,然后点击左边的开始按钮开始运行。 或者直接Ctrl-shift-P,输入launch。 此时打开Launch.json。 改动的地方有: "program": "${workspaceFolder}/${fileBasenameNoExtension}.out", 然后在原来的program下面增加一句: "preLaunchTask": "build",task 选择c/c++ g++那个。 因为是用g++编译的,所以只看命令为g++的部分。也就是最前面的部分。这里是修改过的。 其中改动的地方为: "label": "build",build为Launch.json中"preLaunchTask": “build” 然后参数args里面改一下: "${fileBasenameNoExtension}.out"不然会找不到输出文件。 然后直接运行就好啦。${workspaceRoot} the path of the folder opened in VS Code(VSCode中打开文件夹的路径) ${workspaceRootFolderName} the name of the folder opened in VS Code without any solidus (/)(VSCode中打开文件夹的路径, 但不包含"/") ${file} the current opened file(当前打开的文件) ${relativeFile}the current opened file relative to workspaceRoot(当前打开的文件,相对于workspaceRoot) ${fileBasename}the current opened file’s basename(当前打开文件的文件名, 不含扩展名) ${fileDirname}the current opened file’s dirname(当前打开文件的目录名) ${fileExtname} the current opened file’s extension(当前打开文件的扩展名) ${cwd}the task runner’s current working directory on startup()