目录
一、什么是万能头文件?二、源码三、编译器找不到 `bits/stdc++.h`
一、什么是万能头文件?
C++的万能头文件是:
#include <bits/stdc++.h>
它是一个包含了每一个标准库的头文件。
优点:
在算法竞赛中节约时间;减少了编写所有必要头文件的工作量。缺点:
不是GNU C++库的标准头文件,在部分情况下会编译失败;包含了很多不必要的东西,会大大增加编译时间。二、源码
⚠️ 这里去除了多余的注释,并删除了 cstdalign
。
// C#ifndef _GLIBCXX_NO_ASSERT#include <cassert>#endif#include <cctype>#include <cerrno>#include <cfloat>#include <ciso646>#include <climits>#include <clocale>#include <cmath>#include <csetjmp>#include <csignal>#include <cstdarg>#include <cstddef>#include <cstdio>#include <cstdlib>#include <cstring>#include <ctime>#if __cplusplus >= 201103L#include <ccomplex>#include <cfenv>#include <cinttypes>#include <cstdbool>#include <cstdint>#include <ctgmath>#include <cwchar>#include <cwctype>#endif// C++#include <algorithm>#include <bitset>#include <complex>#include <deque>#include <exception>#include <fstream>#include <functional>#include <iomanip>#include <ios>#include <iosfwd>#include <iostream>#include <istream>#include <iterator>#include <limits>#include <list>#include <locale>#include <map>#include <memory>#include <new>#include <numeric>#include <ostream>#include <queue>#include <set>#include <sstream>#include <stack>#include <stdexcept>#include <streambuf>#include <string>#include <typeinfo>#include <utility>#include <valarray>#include <vector>#if __cplusplus >= 201103L#include <array>#include <atomic>#include <chrono>#include <condition_variable>#include <forward_list>#include <future>#include <initializer_list>#include <mutex>#include <random>#include <ratio>#include <regex>#include <scoped_allocator>#include <system_error>#include <thread>#include <tuple>#include <typeindex>#include <type_traits>#include <unordered_map>#include <unordered_set>#endif
三、编译器找不到 bits/stdc++.h
最简单粗暴的做法就是,首先找到 <iostream>
这个头文件所在的目录,进入该目录,创建名为 bits
的文件夹,再进入该文件夹,创建一个名为 stdc++.h
的文件,把上述源码复制进去即可。