Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include C++ standard library

Tags:

c++

Is it possible to include the C++ standard library in a single statement, or must you do it header by header?

like image 543
xspyderz Avatar asked Feb 26 '12 09:02

xspyderz


People also ask

What is included in standard C library?

The C standard library provides macros, type definitions and functions for tasks such as string handling, mathematical computations, input/output processing, memory management, and several other operating system services.

How many standard libraries are there in C?

The ANSI C standard library consists of 24 C header files which can be included into a programmer's project with a single directive. Each header file contains one or more function declarations, data type definitions and macros.

Is the C standard library written in C?

In a typical case, the C standard library is written primarily in C, and the C++ standard library primarily in C++. To give some concrete numbers, Microsoft's standard library has ~1050 C and C++ files, and 37 assembly language files.

Where can I find C library?

Libaries consist of a set of related functions to perform a common task; for example, the standard C library, 'libc. a', is automatically linked into your programs by the “gcc” compiler and can be found at /usr/lib/libc. a. Standard system libraries are usually found in /lib and /usr/lib/ directories.


2 Answers

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.

like image 63
AndrzejJ Avatar answered Oct 06 '22 02:10

AndrzejJ


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.

like image 26
marcinj Avatar answered Oct 06 '22 03:10

marcinj