提到 STL 算法,大家都知道很牛B。

但是想一想,除了 sort() , 你还会用啥呢?😂

最近抽时间把 STL 所有算法测试一遍,做到心里有个印象。

本文的这些示例基本上都来自于 cppreference.com 和 cplusplus.com

其实就是挨个看一遍,然后复制粘贴一下。

STL algorithms — everyone knows they are awesome.

But think about it: apart from sort(), what else do you actually use? 😂

I recently took some time to test all STL algorithms one by one, so I have a rough idea of what each one does.

The examples in this article basically come from cppreference.com and cplusplus.com

In fact, I just went through them one by one and copy-pasted.

WikiC/C++STL

起因

4 月 13 号早上八点多,我还在睡梦中,被 Telegram 的一条推送吵醒了。

image-20220415144506233

很奇怪,我一个根本没人访问的 WebServer 小项目竟然会自己就宕机了😕。

上午十点睡醒了,起来看一眼日志吧。

好家伙,有人拿我 抄来 的小项目在练手?

Why It Happened

Around 8 am on April 13th, I was still fast asleep when I was woken up by a push notification on Telegram.

image-20220415144506233

Strange — my little WebServer project, which nobody even visits, had crashed all by itself 😕.

I woke up again around 10 am and took a look at the logs.

Well well, someone is practicing on my copied little project?

WikiC/C++

再分享一道笔试题

Another Written Exam Question

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;

int main(){

int a[] = {1,2,3,4,5};
int* p = (int*)(&a + 1);

cout << *(a+1) << ',' << *(p-1) << endl;

return 0;
}

问此程序的输出是多少?

错误答案是 2,1

What is the output of this program?

The wrong answer is 2,1

WikiC/C++笔试

这是一道百度的笔试题

问:关于下面的程序输出为:

  • A:1
  • B:2
  • C:3
  • D:编译无法通过

A Baidu Written Test Question

Q: What does the following program output?

  • A: 1
  • B: 2
  • C: 3
  • D: It won’t compile
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;

void test(int a,int b,int c){
int *p = &b;
cout << *(p-1) << endl;
}

int main(){
test(1,2,3);
return 0;
}

正确答案是…

The correct answer is…

WikiC/C++笔试

C++ 中的 new

C++ 中使用 new 关键字来创建一个对象,创建对象的过程会产生以下操作:

  1. 在内存中申请一块空间,大小为目标对象的大小,并获得该内存空间的地址。
  2. 将该内存空间的地址转换为对象指针。
  3. 通过对象指针调用该对象的构造函数。

new in C++

In C++, the new keyword is used to create an object, and the object creation process involves the following operations:

  1. Allocate a block of memory, sized to the target object, and obtain the address of that memory.
  2. Convert the address of that memory into an object pointer.
  3. Invoke the object’s constructor through the object pointer.
WikiC/C++STL

为了给我的资源分享站和GitHub主页增加一个花里胡哨的Readme,利用 GitHub 上提供的下载 Pixiv 日榜的代码每天定时下载 P 站的日榜,并选择前三张放在 Readme 里。日榜每天都更新,图片每天都要下载,我又是一个喜欢屯东西的人,那么就面临了一个下载下来的图片保存到哪里的问题。一开始想的自然是存到阿里云盘,但是国内提供的服务就是没有隐私可言,存在别人那里的东西都会被人看光光,至少是被阿里云的鉴黄算法看光光😂,于是就出现了下面这种情况。

image-20220209003041597

直接把我图片给删除了!👍

To add a fancy Readme to my resource-sharing site and my GitHub homepage, I used the code GitHub provides for downloading the Pixiv daily ranking to automatically download the daily ranking every day, then put the top three images in the Readme. The daily ranking updates every day, so the images need to be downloaded every day — and since I’m the kind of person who likes to hoard things, I was faced with the question of where to store the downloaded images. At first I naturally thought of Alibaba Cloud Drive, but domestic services simply have no privacy — anything stored on someone else’s server gets seen by everyone, at least by Alibaba Cloud’s porn-detection algorithm 😂, and that’s how the situation below came about.

image-20220209003041597

It straight-up deleted my images! 👍

教程WikiGitHubPython