败犬日报 2025-12-31
败犬日报 2025-12-31
1. Cpp错误处理杂谈(文章)
https://zhuanlan.zhihu.com/p/643809540
2. “可执行”的 C++ 源文件
cpp
//usr/bin/true ; TMP_OUT=$(mktemp) ; /usr/bin/env c++ "$0" -o "${TMP_OUT}" ; exec -a "$0" "${TMP_OUT}" "$0" ; rm "${TMP_OUT}" ; exit
#include <iostream>
int main(int argc, char** argv) {
std::cout << argc << std::endl;
for (int i = 0; i < argc; i++) {
std::cout << argv[i] << std::endl;
}
return 0;
}用 shell 执行就会编译运行代码,用了一些操作让 argv[0] 正确传递。