Include bits std c

Я отправил вопрос с моим кодом, чей единственный #include Директива была следующей:

Мой учитель сказал мне сделать это, но в разделе комментариев мне сообщили, что я не должен.

Решение

В том числе Похоже, что все чаще можно увидеть о переполнении стека, возможно, что-то новое, добавленное в национальную учебную программу в текущем учебном году.

Я предполагаю, что преимущества расплывчато

  • Вам нужно только написать один #include линия
  • Вам не нужно искать, в каком стандартном заголовке все находится

К сожалению, это ленивый взлом, называть внутренний заголовок GCC напрямую вместо отдельных стандартных заголовков, таких как , а также , Это разрушает мобильность и воспитывает ужасные привычки.

К недостаткам относятся:

  • Вероятно, он будет работать только на этом компиляторе
  • Вы не представляете, что он будет делать, когда вы его используете, потому что его содержимое не установлено стандартом
  • Даже простое обновление вашего компилятора до следующей версии может сломать вашу программу
  • Каждый стандартный заголовок должен анализироваться и компилироваться вместе с исходным кодом, что является медленным и приводит к громоздкому исполняемому файлу при определенных настройках компиляции.

It is basically a header file that includes every standard library. In programming contests, using this file is a good idea, when you want to reduce the time wasted in doing chores; especially when your rank is time sensitive.
In programming contests, people do focus more on finding the algorithm to solve a problem than on software engineering. From, software engineering perspective, it is a good idea to minimize the include. If you use it actually includes a lot of files, which your program may not need, thus increases both compile time and program size unnecessarily.

Disadvantages of bits/stdc++

  • bits/stdc++.h is not a standard header file of GNU C++ library. So, if you try to compile your code with some compiler other than GCC it might fail; e.g. MSVC do not have this header.
  • Using it would include a lot of unnecessary stuff and increases compilation time.
  • This header file is not part of the C++ standard and is therefore, non-portable, and should be avoided.
  • Moreover, even if there were some catch-all header in the standard, you would want to avoid it in lieu of specific headers, since the compiler has to actually read in and parse every included header (including recursively included headers) every single time that translation unit is compiled.

Advantages of bits/stdc++

  • In contests, using this file is a good idea, when you want to reduce the time wasted in doing chores; especially when your rank is time sensitive.
  • This also reduces all the chores of writing all the necessary header files.
  • You don’t have to remember all the STL of GNU C++ for every function you use.

So, the user can either use it and save the time of writing every include or save the compilation time by not using it and writing necessary header files.

This article is contributed by Ayush Govil. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

This question already has an answer here:

I have read from a codeforces blog that if we add #include in a C++ program then there is no need to include any other header files. How does #include work and is it ok to use it instead of including individual header files?

marked as duplicate by Matthieu Brucher, πάντα ῥεῖ c++ Users with the c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed. Nov 1 ’18 at 11:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

6 Answers 6

It is basically a header file that also includes every standard library and STL include file. The only purpose I can see for it would be for testing and education.

Using it would include a lot of unnecessary stuff and increases compilation time.

Edit: As Neil says, it’s an implementation for precompiled headers. If you set it up for precompilation correctly it could, in fact, speed up compilation time depending on your project. (https://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html)

I would, however, suggest that you take time to learn about each of the sl/stl headers and include them separately instead, and not use "super headers" except for precompilation purposes.

#include is an implementation file for a precompiled header.

From, software engineering perspective, it is a good idea to minimize the include. If you use it actually includes a lot of files, which your program may not need, thus increase both compile-time and program size unnecessarily. [edit: as pointed out by @Swordfish in the comments that the output program size remains unaffected. But still, it’s good practice to include only the libraries you actually need, unless it’s some competitive competition]

But in contests, using this file is a good idea, when you want to reduce the time wasted in doing chores; especially when your rank is time-sensitive.

It works in most online judges, programming contest environments, including ACM-ICPC (Sub-Regionals, Regionals, and World Finals) and many online judges.

The disadvantages of it are that it:

  • increases the compilation time.
  • uses an internal non-standard header file of the GNU C++ library, and so will not compile in MSVC, XCode, and many other compilers

That header file is not part of the C++ standard, is therefore non-portable, and should be avoided.

Moreover, even if there were some catch-all header in the standard, you would want to avoid it in lieu of specific headers, since the compiler has to actually read in and parse every included header (including recursively included headers) every single time that translation unit is compiled.

It is basically a header file that includes every standard library. In programming contests, using this file is a good idea, when you want to reduce the time wasted in doing chores; especially when your rank is time-sensitive. In programming contests, people do focus more on finding an algorithm to solve a problem than on software engineering. From, software engineering perspective, it is a good idea to minimize the include. If you use it actually includes a lot of files, which your program may not need, thus increases both compile-time and program size unnecessarily.

Visit this for more detail.

This is best thing for Online coding where speed matters a lot.

Unfortunately that approach is not portable C++ (so far).

All standard names are in namespace std and moreover you cannot know which names are NOT defined by including and header (in other words it’s perfectly legal for an implementation to declare the name std::string directly or indirectly when using #include ).

Despite this however you are required by the language to know and tell the compiler which standard header includes which part of the standard library. This is a source of portability bugs because if you forget for example #include but use std::map it’s possible that the program compiles anyway silently and without warnings on a specific version of a specific compiler, and you may get errors only later when porting to another compiler or version.

In my opinion there are no valid technical excuses because this is necessary for the general user: the compiler binary could have all standard namespace built in and this could actually increase the performance even more than precompiled headers (e.g. using perfect hashing for lookups, removing standard headers parsing or loading/demarshalling and so on).

The use of standard headers simplifies the life of who builds compilers or standard libraries and that’s all. It’s not something to help users.

However this is the way the language is defined and you need to know which header defines which names so plan for some extra neurons to be burnt in pointless configurations to remember that (or try to find and IDE that automatically adds the standard headers you use and removes the ones you don’t. a reasonable alternative).


[an error occurred while processing the directive]
Карта сайта