简体   繁体   中英

Include C++ standard library

是否可以在单个语句中包含 C++ 标准库,还是必须逐个标题?

No, there is no shortcut to include all of the standard headers. You must generally include each one that you require separately.

It's possible to create a single header file that includes all standard library headers—something like all.h . However, you should consider whether doing that is a smart move, as it will extend compilation times significantly.

Also, make sure you understand the C++ compilation model before you make such decisions. If you don't already know, find out what's a translation unit, an object file, what the linker does, what's the difference between including a library header and linking a library.

Under Visual Studio you could put all such header files inside your precompiled header file. Since this file is included by all your files all stl hearders would be available everywhere. If all the includes in precompiled header file are from external libraries, then precompilation should speed up compilation times.

GCC has a header called <bits/stdc++.h> , but this should never be relied on in a typical context.

As noted by the OP, this is the kind of thing you might only want to use in a competitive programming contest, where only running time matters.

不,没有包含所有标准标题的快捷方式。

也许您可以在自己的all.h包含所有标题,然后是#include<all.h> ,但不建议这样做。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM