0% found this document useful (0 votes)
4 views3 pages

C++ Shortcut Key

The bits/stdc++.h header is a GCC-specific precompiled header that includes nearly all standard C++ headers, providing access to various built-in functions and algorithms. It covers math, algorithm, string functions, STL utilities, numeric functions, and random number generation, with examples for each. However, it is not part of the official C++ standard and may not be compatible with all compilers, so for portable code, specific headers should be included instead.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

C++ Shortcut Key

The bits/stdc++.h header is a GCC-specific precompiled header that includes nearly all standard C++ headers, providing access to various built-in functions and algorithms. It covers math, algorithm, string functions, STL utilities, numeric functions, and random number generation, with examples for each. However, it is not part of the official C++ standard and may not be compatible with all compilers, so for portable code, specific headers should be included instead.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

The bits/stdc++.

h header is a GCC-specific precompiled header that includes almost all standard


C++ headers. It provides access to many built-in functions and algorithms from the C++ Standard
Library.
Here is a list of commonly used built-in functions available under bits/stdc++.h:

1. Math Functions (cmath)

Function Description Example

abs(x) Absolute value abs(-5) → 5

sqrt(x) Square root sqrt(25) → 5

pow(x, y) Power function (x^y) pow(2, 3) → 8

ceil(x) Round up to nearest integer ceil(4.2) → 5

floor(x) Round down to nearest integer floor(4.9) → 4

round(x) Round to nearest integer round(4.5) → 5

log(x) Natural logarithm (ln x) log(10) → 2.302

log10(x) Log base 10 log10(100) → 2

sin(x), cos(x), tan(x) Trigonometric functions sin(90) (in radians)

2. Algorithm Functions (algorithm)

Function Description Example

min(a, b) Returns the smaller of a and b min(10, 20) → 10

max(a, b) Returns the larger of a and b max(10, 20) → 20

swap(a, b) Swaps two values swap(x, y)

sort(begin, end) Sorts a range sort(arr, arr+n)

reverse(vec.begin(),
reverse(begin, end) Reverses a range
vec.end())
Function Description Example

next_permutation(begin, Generates the next lexicographic


end) permutation

prev_permutation(begin,
Generates the previous permutation
end)

binary_search(begin, end, x) Checks if x exists in sorted range

lower_bound(begin, end, x) First position >= x in sorted array

upper_bound(begin, end, x) First position > x in sorted array

3. String Functions (string)

Function Description Example

s.length() Returns string length string s = "hello"; s.length() → 5

s.substr(pos, len) Extracts substring s.substr(1, 3) → "ell"

s.find(str) Finds substring position s.find("lo") → 3

s.append(str) Appends string s.append(" world") → "hello world"

s.erase(pos, len) Erases part of string s.erase(1, 2) → "ho"

s.insert(pos, str) Inserts string at position s.insert(2, "xx") → "hexxllo"

s.replace(pos, len, str) Replaces part of string s.replace(1, 2, "yy") → "hyylo"

s.compare(str) Compares strings lexicographically

4. STL (Standard Template Library) Utilities

Function Description Example

pair<int, int> p; Pair of values p = make_pair(10, 20);

vector<int> v; Dynamic array v.push_back(10);

map<int, int> mp; Key-value dictionary mp[1] = 100;


Function Description Example

set<int> s; Stores unique values s.insert(5);

priority_queue<int> pq; Max heap pq.push(10);

queue<int> q; FIFO queue q.push(1); q.pop();

5. Numeric Functions (numeric) (C++17 and later)

Function Description Example

std::gcd(a, b) Computes GCD std::gcd(10, 20) → 10

std::lcm(a, b) Computes LCM std::lcm(10, 20) → 20

accumulate(begin, end, init) Sum of elements in a range

6. Random Number Generation (cstdlib and random)

Function Description Example

rand() Generates a random number rand() % 100 (0 to 99)

srand(time(0)) Seeds random generator

Conclusion

The bits/stdc++.h header includes all these standard functions but is not part of the official C++ standard.
It is GCC-specific and may not work in all compilers like MSVC. If you want portable code, include specific
headers instead (e.g., <algorithm>, <cmath>, <string>).

You might also like