StephEric

Department of Computer Science and Technology, Tsinghua University

0%

安装g++编译器

1
2
sudo apt update
sudo apt install g++

检查是否安装正确

1
g++ --version

如果正确显示了g++的版本,那么表示安装成功 Linux 平台自带了 gcc 和 make 等等编译工具,所以不需要进行额外的配置。

配置编译和调试文件

安装插件WSL 后选择connect to WSL

按快捷键F5 进行编译,会在.vscode里生成launch.json文件,按照下面的表进行配置即可,注意与windows有细微的区别

launch.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{

    "version": "0.2.0",

    "configurations": [

        {//这个大括号里是我们的‘调试(Debug)’配置

            "name": "Debug", // 配置名称

            "type": "cppdbg", // 配置类型,cppdbg对应cpptools提供的调试功能;可以认为此处只能是cppdbg

            "request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)

            "program": "${fileDirname}/bin/${fileBasenameNoExtension}.exe", // 将要进行调试的程序的路径

            "args": [], // 程序调试时传递给程序的命令行参数,这里设为空即可

            "stopAtEntry": false, // 设为true时程序将暂停在程序入口处,相当于在main上打断点

            "cwd": "${fileDirname}", // 调试程序时的工作目录,此处为源码文件所在目录

            "environment": [], // 环境变量,这里设为空即可

            "externalConsole": false, // 为true时使用单独的cmd窗口,跳出小黑框;设为false则是用vscode的内置终端,建议用内置终端

            "internalConsoleOptions": "neverOpen", // 如果不设为neverOpen,调试时会跳到“调试控制台”选项卡,新手调试用不到

            "MIMode": "gdb", // 指定连接的调试器,gdb是minGW中的调试程序

            "miDebuggerPath": "/usr/bin/gdb", // 指定调试器所在路径,如果你的minGW装在别的地方,则要改成你自己的路径,注意间隔是/

            "preLaunchTask": "C/C++: g++ build active file" // 调试开始前执行的任务,我们在调试前要编译构建。与tasks.json的label相对应,名字要一样

    }]

}

tasks.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{

    "version": "2.0.0",

    "tasks": [

        {

            "type": "cppbuild",

            "label": "C/C++: g++ build active file",

            "command": "g++",

            "args": [

                "-fdiagnostics-color=always",

                "-g",

                "${file}",

                "-o",

                "${fileDirname}/bin/${fileBasenameNoExtension}.exe",

                "-std=c++14",

                "-Wall",

                "-static-libgcc",

                //"-fexec-charset=GBK"

            ],

            "options": {

                "cwd": "${fileDirname}"

            },

            "problemMatcher": [

                "$gcc"

            ],

            "group": "build",

            "detail": "compiler: /usr/bin/g++"

        },

             {//这个大括号里是‘运行(run)’任务,一些设置与上面的构建任务性质相同

             "label": "run",

             "type": "shell",

             "dependsOn": "build", //任务依赖,因为要运行必须先构建,所以执行这个任务前必须先执行build任务,

             "command": "${fileDirname}/bin/${fileBasenameNoExtension}.exe", //执行exe文件,只需要指定这个exe文件在哪里就好

             "group": {

                 "kind": "test", //这一组是‘测试’组,将run任务放在test组里方便我们用快捷键执行

                 "isDefault": true

             },

             "presentation": {

                 "echo": true,

                 "reveal": "always",

                 "focus": true, //这个就设置为true了,运行任务后将焦点聚集到终端,方便进行输入

                 "panel": "new"

             }

         }

    ]

}

本博客记录我配置[[WSL]]环境的过程及一些踩坑点。Windows系统为Windows11 21H2 home edition,安装Ubuntu 22.04.1 LTS (GNU/Linux 5.15.90.1-microsoft-standard-WSL2 x86_64)。

更换ubuntu存储位置

因为目前用的电脑是512G,分开了C盘和D盘。WSL的默认安装位置为C盘,所以希望将之后Linux安装的各种环境配置包转移到D盘。

我主要参考了这篇WSL2文件迁移到D盘

阅读全文 »

首先,我想要试图卸载VMware Workstation Pro16 并升级成 17,但是其中一个.msi文件丢掉了,就是因为我换电脑的时候,只迁移了一点东西,没有迁移Programs(X86)。升级17需要先卸载16,这样它找不到16的安装源,就寄掉了。

我去问ChatGPT,

支持修改元素值的优先[[队列]]

If you want to modify an element in a priority queue, you would need to remove the element, modify it, and then insert it back into the priority queue. However, this can be inefficient for large priority queues since removing and inserting elements can be expensive operations.

In C++, the standard priority queue container does not provide a direct way to modify elements. Instead, you would need to implement a custom priority queue data structure that allows efficient modification of elements.

One way to do this is to use a combination of a heap-based priority queue and a hash table (or a map) that maps elements to their positions in the heap. The hash table allows fast lookup of an element's position in the heap, and the heap-based priority queue allows efficient access to the highest-priority element.

Here is a simple example of a custom priority queue data structure that supports efficient modification of elements:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <queue>
#include <unordered_map>

template <typename T>
class CustomPriorityQueue {
public:
void push(const T& val) {
pq.push(val);
pos[val] = pq.size() - 1;
}

void pop() {
pos.erase(pq.top());
pq.pop();
}

void modify(const T& old_val, const T& new_val) {
auto it = pos.find(old_val);
if (it == pos.end()) {
return;
}

int i = it->second;
pq.pop();

if (i != pq.size()) {
pq.push(pq.top());
pos[pq.top()] = i;
pq.pop();
}

pos.erase(it);
push(new_val);
}

const T& top() const {
return pq.top();
}

bool empty() const {
return pq.empty();
}

private:
std::priority_queue<T> pq;
std::unordered_map<T, int> pos;
};

表格

数学

分段函数

1
2
3
4
5
f(x) =
\begin{cases}
2x + 1, & \text{如果} \quad x < 0 \\
x^2, & \text{如果} \quad x \geq 0
\end{cases}

[[LaTeX分段函数配图.png|425]]

KMP算法解决了子串在字符串中定位的问题,即子串查找与匹配。KMP算法是三位大佬D.E.Knuth、J.H.Morris和V.R.Pratt同时发现的。

阅读全文 »

本文总结C语言课程学习中用到的指针概念及操作。

阅读全文 »