Compare commits

..

6 Commits

Author SHA1 Message Date
Kane 4f7abee677 保存进度 2026-07-24 00:05:10 +08:00
Kane b96d094bd2 保存进度! 2026-07-21 19:32:30 +08:00
Kane ad7545fec1 保存进度! 2026-07-20 19:02:32 +08:00
Kane b17276e0b2 保存进度! 2026-07-20 11:46:45 +08:00
Kane 82fd2be5a1 Merge branch 'main' of http://222.76.244.118:3000/Kane/cpp-study
新建学习项目。
2026-07-14 23:22:10 +08:00
Kane 79c836426c 保存进度 2026-07-14 23:20:12 +08:00
13 changed files with 526 additions and 0 deletions
+2
View File
@@ -447,3 +447,5 @@ CTestTestfile.cmake
_deps
CMakeUserPresets.json
/net-commander
+22
View File
@@ -0,0 +1,22 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"D:\\develop\\sdk\\cpp\\boost\\build\\boost_1_89_0_msvc2022\\include\\boost-1_89"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.26100.0",
"compilerPath": "cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
+73
View File
@@ -0,0 +1,73 @@
/**
* This file is generated by VSCode extension: Fileheader Pro
*/
/**
* These comments can help you write your own template with type hint
* @typedef {Object} FileheaderVariable Fileheader variables
* @property {string} birthtime file birth time. will get it from VCS or fallback to filesystem when it is not available
* @property {string} mtime file modification time. will get it from VCS or fallback to filesystem when it is not available
* @property {string} authorName if the file is tracked by VCS, it will get the author name from VCS. else it will get it from current user name
* @property {string} authorEmail if the file is tracked by VCS, it will get the author email from VCS. else it will get it from current user email
* @property {string} userName else it will get it from current user name
* @property {string} userEmail user email is from VSCode config, and fallback to VCS config
* @property {string} companyName
* @property {string} projectName name of current project
* @property {string} filePath the file path, relative to project root with POSIX path separator
* @property {string} dirPath the directory path, relative to project root with POSIX path separator
* @property {string} fileName filename with extension
*/
/**
* @typedef {string | number | null | undefined | Template | boolean} TemplateInterpolation NOTE: boolean or falsy value will render empty string
*
* @typedef {{ strings: TemplateStringsArray; interpolations: TemplateInterpolation[]; }} Template
* @typedef {(strings: TemplateStringsArray, ...values: any[]) => string} ITemplateFunction
*
*/
/**
* Please confirm your provider extends from globalThis.FileheaderLanguageProvider
*/
class CustomLanguageProvider extends globalThis.FileheaderLanguageProvider {
/**
* @type {string[]}
*/
languages = [
"javascript",
"typescript",
"javascriptreact",
"typescriptreact",
];
/**
* @type {string=} the language block comment start string.
* this is for future feature: support detect old custom template when custom template changes
*/
blockCommentStart = "/*";
/**
* @type {string=}
*/
blockCommentEnd = "*/";
/**
* get your template when document language matched
* @param {ITemplateFunction} tpl template function, it is a tagged function, support nested interpolation
* @param {FileheaderVariable} variables template variables
* @returns {Template}
*/
getTemplate(tpl, variables) {
// prettier-ignore
return tpl
`/*
* @author ${variables.authorName} <${variables.authorEmail}>
* @date ${variables.birthtime}
* @lastModified ${variables.mtime}
* Copyright © ${variables.companyName} All rights reserved
*/`;
}
}
// export your provider classes
module.exports = [CustomLanguageProvider];
+30
View File
@@ -0,0 +1,30 @@
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "MSVC 调试 Boost 程序",
"type": "cppvsdbg",
"request": "launch",
// 编译输出的exe路径,根据你项目修改
"program": "${workspaceFolder}/out/bin/debug/main.exe",
"args": [], // 程序启动参数
"stopAtEntry": false, // 是否在main第一行自动断点
"cwd": "${workspaceFolder}", // 工作目录
"environment": [
// Boost库路径,运行时加载dll
{
"name": "PATH",
"value": "${workspaceFolder}/out/bin/debug;${env:PATH};D:/develop/sdk/cpp/boost/build/boost_1_89_0_msvc2022/lib"
}
],
"externalConsole": false, // true弹出黑窗口,false内置终端
"symbolSearchPath": "${workspaceFolder}/stage/lib/x64-msvc-14.3/debug",
"logging": {
"moduleLoad": false
}
}
]
}
+45
View File
@@ -0,0 +1,45 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "msvc2022 调试编译",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/nologo",
"/Fe${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
"options": {
"cwd": "${fileDirname}",
},
"problemMatcher": [ // 错误信息匹配器,有$msCompiler、$gcc 选项
"$msCompile" // 使用msvc编辑器的匹配器,
],
"group": {
"kind": "build",
"isDefault": false,
},
"detail": "编译器: cl.exe"
},
{
"type":"cppbuild",
"label": "msvc2022 生产编译",
"command": "cl.exe",
"args": [
"/EHsc",
"/nologo",
"/Fe${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
"options": {
"cwd": "${fileDirname}"
}
}
]
}
+14
View File
@@ -0,0 +1,14 @@
BOOST_DIR=D:\develop\sdk\cpp\boost\build\boost_1_89_0_msvc2022
BOOST_INCLUDE_DIR=D:\develop\sdk\cpp\boost\build\boost_1_89_0_msvc2022\include\boost-1_89
BOOST_LIB_DIR=$(BOOST_DIR)\lib
CXXFLAGS=/I $(BOOST_INCLUDE_DIR) /MT /EHsc
LINKFLAGS=/LIBPATH:$(BOOST_LIB_DIR)
# all: static boost.exe shared boost.exe
static_2.exe: ./code/main.cpp
cl ./code/main.cpp $(CXXFLAGS) /Fe"static_2.exe" /link $(LINKFLAGS)
clean:
del *.obj
+284
View File
@@ -0,0 +1,284 @@
# VS Code tasks.json 完整参数说明文档
## 文档说明
本文档覆盖 `tasks.json` 顶层配置、单任务全部字段、跨平台配置、内置变量、完整可运行示例,适配 Windows MSVC + Boost b2 C++ 构建场景。
## 一、tasks.json 顶层根字段
```
{
"version": "2.0.0",
"tasks": [],
"inputs": []
}
```
表格
| 字段 | 作用 |
| --- | --- |
| `version` | 任务配置标准版本号,固定填写 `2.0.0`,不可修改 |
| `tasks` | 数组,存放所有构建任务,每一项为独立编译 / 清理脚本 |
| `inputs` | 自定义交互式输入配置,用于弹窗手动传入参数(进阶) |
## 二、单个任务核心配置(tasks 数组内对象)
### 1. 基础标识字段
#### label(必填)
任务显示名称,两处关键用途:
1. `Ctrl+Shift+B` 下拉列表展示名称
2. `launch.json``preLaunchTask` 通过该名称绑定编译任务
```
"label": "Boost Build Debug"
```
#### type(任务执行类型,三选一)
表格
| 取值 | 适用场景 | 特点 |
| --- | --- | --- |
| `shell` | Windows cmd/PowerShell、Linux bash | 支持 `&&`、管道等多条命令串联,C++ Windows 首选 |
| `process` | 直接运行 exe 可执行文件(b2.exe/cl.exe | 不经过系统 shell,性能更高,不支持多条命令拼接 |
| `npm` | 前端 Node 项目 | C++ 开发无需使用 |
| `cppbuild` | 用于 C/C++ 项目的编译任务 | |
#### command
要执行的命令 / 可执行文件:
- `type: shell`:可简写命令名 `b2``cl`
- `type: process`:必须写完整相对路径 `./b2.exe`
- `type:cppbuild`: 可以写`cl.exe`
#### args
命令行参数数组,每个参数单独一项,自动分隔空格,无需手动拼接空格。
示例:`b2 toolset=msvc variant=debug stage`
```
"args": ["toolset=msvc", "variant=debug", "stage"]
```
### 2. 构建分组 group(快捷键绑定)
控制 `Ctrl+Shift+B` 行为
```
"group": {
"kind": "build",
"isDefault": true
}
```
- `kind: "build"`:归类为构建任务,快捷键调出
- `kind: "test"`:归类为测试任务
- `isDefault: true`:按下 `Ctrl+Shift+B` 直接执行该任务
### 3. problemMatcher 编译错误捕获(关键功能)
将编译器报错、警告同步到 VSCode「问题」面板,点击直接跳转代码行。
内置模板直接使用:
表格
| 模板值 | 适用编译器 |
| --- | --- |
| `$msCompile` | MSVC cl.exe、Boost b2Windows C++ |
| `$gcc` | MinGW GCC、Linux GCC |
自定义模式:自行编写正则解析日志(极少使用)
```
"problemMatcher": "$msCompile"
```
### 4. options 运行环境配置
控制任务工作目录、临时环境变量
#### cwd
任务执行的工作目录,命令在此路径运行
```
"options": {
"cwd": "${workspaceFolder}"
}
```
#### env
仅当前任务生效的临时环境变量,不修改系统全局环境
```
"options": {
"env": {
"PATH": "D:/boost/stage/lib;${env:PATH}",
"BOOST_ROOT": "D:/boost"
}
}
```
### 5. 跨平台差异化配置 windows /linux/osx
三套系统独立配置,优先级高于外层通用配置,Windows 用于自动加载 MSVC 编译环境。
```
"windows": {
"options": {
"shell": {
"executable": "cmd.exe",
"args": ["/C", "VsDevCmd.bat &&"]
}
}
},
"linux": {},
"osx": {}
```
### 6. shell 终端自定义(仅 type=shell 生效)
```
"shell": {
"executable": "cmd.exe",
"args": ["/C"],
"env": {}
}
```
- `executable`:指定终端程序 cmd /powershell/bash
- `args`:终端启动参数,`/C` 代表执行完命令关闭窗口
### 7. presentation 终端展示样式
控制任务终端弹窗行为
```
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "new",
"clear": true
}
```
表格
| 参数 | 说明 |
| --- | --- |
| echo | 终端打印完整执行命令 |
| reveal | always 自动弹出;silent 仅报错弹出;never 不弹出 |
| focus | 任务运行后是否自动聚焦终端 |
| panel | new 新建终端;shared 共用;dedicated 专属终端 |
| clear | 执行前清空终端历史日志 |
### 8. dependsOn 任务串行依赖
先执行依赖任务,再运行当前任务,常用于「清理 → 编译」流程
```
"dependsOn": ["Clean Boost"]
```
支持数组多任务,按数组顺序依次执行。
### 9. runOn 自动触发任务
可选值 `folderOpen`:打开项目文件夹自动运行该任务
```
"runOn": "folderOpen"
```
### 10. ignoreError
- `false`(默认):命令返回错误码(编译失败),标记任务失败、中断流程
- `true`:忽略错误码,继续执行后续流程
## 三、全局内置路径变量(所有字段通用)
推荐使用变量,适配不同电脑路径,避免硬编码
表格
| 变量 | 含义 |
| --- | --- |
| `${workspaceFolder}` | 项目根目录 |
| `${workspaceFolderBasename}` | 项目文件夹名称 |
| `${file}` | 当前打开文件完整路径 |
| `${fileDirname}` | 当前文件所在文件夹 |
| `${env:XXX}` | 读取系统环境变量,例 `${env:PATH}` |
| `${cwd}` | 当前工作目录 |
## 四、完整注释示例(Boost b2 Windows MSVC
```
{
"version": "2.0.0",
"tasks": [
{
"label": "Boost Build Debug",
"type": "shell",
"command": ".\\b2.exe",
"args": ["toolset=msvc", "variant=debug", "stage"],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": "$msCompile",
"options": {
"cwd": "${workspaceFolder}"
},
"presentation": {
"clear": true,
"reveal": "always"
},
"windows": {
"options": {
"shell": {
"executable": "cmd.exe",
"args": ["/C", "C:\\Program Files (x86)\\Microsoft Visual Studio\\18\\BuildTools\\Common7\\Tools\\VsDevCmd.bat &&"]
}
}
}
},
{
"label": "Boost Build Release",
"type": "shell",
"command": ".\\b2.exe",
"args": ["toolset=msvc", "variant=release", "stage"],
"group": "build",
"problemMatcher": "$msCompile",
"options": {
"cwd": "${workspaceFolder}"
}
},
{
"label": "Clean Boost",
"type": "shell",
"command": ".\\b2.exe clean",
"options": {
"cwd": "${workspaceFolder}"
}
}
]
}
```
## 五、高频实用场景总结
1. **自动加载 MSVC 编译环境**:配置 `windows.shell` 执行 `VsDevCmd.bat`
2. **调试前自动编译**`launch.json` 中配置 `"preLaunchTask": "任务label"`
3. **编译错误跳转代码**:配置 `problemMatcher: "$msCompile"`
4. **先清理再编译**:添加 `dependsOn` 绑定清理任务
5. **临时追加库搜索路径**`options.env` 追加 PATH 环境变量
6. **一键编译快捷键**`group.isDefault: true`,使用 `Ctrl+Shift+B`
+25
View File
@@ -0,0 +1,25 @@
#include <iostream>
#include <boost/regex.hpp>
#include ".\message\message.h"
using namespace std;
using namespace boost;
extern const string MESSAGE;
int main()
{
string s = R"(Search Engines: http://baidu.com https://google.com About Me: https://xuhongxu.com/about/)";
regex e("(([a-zA-Z]*)://\\[a-zA-Z0-9\\_-\\]+(\\.\\[a-zA-Z0-9\\_-\\]+)+(/\\[^\\s<>\"\\)\\]\\*)?");
for (sregex_iterator m(s.begin(), s.end(), e), end; m != end; ++m)
{
cout << "URL: " << (*m)[0].str() << endl;
cout << "Scheme: " << (*m)[1].str() << endl;
cout << endl;
}
cout << "结束" << endl;
return 0;
}
Binary file not shown.
+10
View File
@@ -0,0 +1,10 @@
#include "message.h"
using namespace std;
static const string MESSAGE = "Hello World Message!";
void printMessage()
{
std::cout << MESSAGE;
}
+9
View File
@@ -0,0 +1,9 @@
#include <string>
#include <iostream>
using std::string;
using std::cout;
extern const string MESSAGE;
void printMessage();
Binary file not shown.
+12
View File
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.20)
set("a?b" "变量ab")
set( fenhao a;b;c d e f )
#这是注释
#[[注释啊注释
]]#
message( ${fenhao} )