我写了一个实例程序(不重要)
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(void)
{
fstream iofile("test.txt");
vector<string> strs(20);
int i=0;
if(!iofile){
cerr<<"open file failed"<<endl;
}else{
while(iofile>>strs[i++]);
}
for(int j=0;j<i-1;j++)
{
cout<<strs[j]<<endl;
}
// cout<<endl;
cout<<"after sort"<<endl;
cout<<*(strs.begin())<<endl;
sort(strs.begin(),strs.begin()+i-1);
cout<<"i:"<<i<<" "<<strs[1]<<endl;
for(int j=0;j<i;j++)
{
cout<<strs[j]<<" ";
}
cout<<endl;
return 0;
}
这个时候,我们按F5,发现不能运行,它提示需要一个Launch.json文件,OK,这是一个启动文件,我们来配置它。
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build",
"preLaunchTask": "build",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
注意,这里需要修改的部分主要是program那一行,仅需修改为自己编译后产生的文件名,不如g++ -g 1.7.cpp -o build,所以这里我就取了build这个名字。
还有,就是要添加preLaunchTask这一行,名字与下面的task要对应。
这里,它还需要一个task.json文件,配置如下,
{
// See https://