惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
月光博客
月光博客
aimingoo的专栏
aimingoo的专栏
Google DeepMind News
Google DeepMind News
Recent Announcements
Recent Announcements
MyScale Blog
MyScale Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
F
Fortinet All Blogs
小众软件
小众软件
D
Docker
U
Unit 42
博客园 - 聂微东
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
爱范儿
爱范儿
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
有赞技术团队
有赞技术团队
腾讯CDC

kkocdko's blog

Compressibility detection in btrfs and zstd Tasker 永久试用修改思路 - kkocdko's blog 极限压缩文档扫描件 - kkocdko's blog Bypass the Blank Chars Detection crknob - Chrome portable patch 我如何将博客首页体积降至 3 KB - kkocdko's blog 如何极限优化压缩文件体积 - kkocdko's blog EmEditor 精简版 - kkocdko's blog Backup Data from VSCode Web 优雅地游玩 Minecraft - kkocdko's blog 让程序以管理员权限运行的 PE 清单 - kkocdko's blog 注销 ZEIT 账号之后遇到的坑 - kkocdko's blog 本博客的协议已更改为 CC0 - kkocdko's blog mobp - 使 MSOffice 后台常驻 在安装 VS 生成工具时规避 .NET 安装错误 各种格式的占位空文件 - kkocdko's blog 优雅地游玩 Flash 游戏 - kkocdko's blog WPS 2016 极限精简版 - kkocdko's blog Convert Const to Let by Terser 规避 Visual Studio 许可证过期的 Bug 方便地使用 iPod - kkocdko's blog 用 UserJS 注入 UserCSS - kkocdko's blog 注册表修改文件关联(默认程序) - kkocdko's blog 周期精准的太阳系模型 - kkocdko's blog 关闭屏幕的 WinAPI - kkocdko's blog 重置 Windows 图标缓存 - kkocdko's blog AIDA64 极限精简单文件版 - kkocdko's blog 几何画板单文件精简版 - kkocdko's blog 世界之窗浏览器单文件版 - kkocdko's blog 在 MBR + Legacy 下用 Bootmgr 引导 Ubuntu
Tricks for C++ Simple App Development
2026-04-11 · via kkocdko's blog

This tutorial is not a primer guide, nor will there be much detail.

My scenarios: Algorithm Learning.

Switch to Linux

Compilers work faster on Linux most of the time, and many tools only run on Linux.

Fedora is the distribution I'm using.

Then you should install the GCC, on Fedora it's dnf install gcc-c++. Search "Install GCC Your Distribution" for more.

MOLD Linker

Install mold. Although we are just writing a simple app, mold still made the build a little faster.

VSCode and Clangd

Install VSCode for editing and Clangd Extension for intellisense.

Clangd is much faster than Microsoft's C/C++ extension.

If you want a debug support, try Native Debug or CodeLLDB.

Project Structure & Others

Create a folder named hello-cpp like this:

├─ build
├─ src
│  └─ main.cc
└─ utils
   ├─ mold
   ├─ mold-wrapper.so
   └─ run.sh

The content of ./utils/run.sh:

# \time -f %e \
~/utils/mold -run g++ ./src/main.cc -o ./build/main -Wall -Wextra -g -fsanitize=undefined -fsanitize=address -fno-omit-frame-pointer
ulimit -t 1 # avoid infinity loop
[ $? -eq 0 ] && ./build/main
# readelf -p .comment ./build/main

Switch -fsanitize=address is used to enable AddressSanitizer.

Then you can create a build task to execute ./utils/run.sh and bind a key shortcut.

Don't include unnecessary headers. #include <bits/stdc++.h> caused heavily compile time, only use it when submitting to Online Judge.

Redirect cin

The common way to redirect the stdin is freopen("in.txt", "r", stdin), but creating extra file is annoying, so here a more concise way:

stringstream fcin(R"(1
3
1 2 3)");
istream std::cin(fcin.rdbuf());

Old compilers may be unsupported.