
- C++ Library - Home
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- The C++ STL Library
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- The C++ Advanced Library
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ STL Library Cheat Sheet
- C++ STL - Cheat Sheet
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
C++ Library -
The
In C++
Including Header
To include the
#include
Functions of Header
Below is list of all functions from
String Conversion
These functions are used for converting strings (C-style strings) to numerical values such as integers and floating numbers or to convert numbers to strings. The commonly used C++
Sr.No | Functions & Description |
---|---|
1 |
atof
It converts a string to a floating point value. |
2 |
atoi & atol & atoll
It converts a string to an integer value. |
3 |
strtoul & strtoull
It converts a string to a unsigned integer value. |
4 |
strtof & strtod & strtold
It converts a string to a floating point value. |
String to Integer Conversion
In the following example, we are going to use the atoi to convert the string to an integer.
#include#include int main() { const char * x = "11123"; int y = std::atoi(x); std::cout << "Result : " << y << std::endl; return 0; }
Output
Output of the above code is as follows −
Result : 11123
Process Control
These functions are used to manage and control program executions. They include operations such as program termination, environment manipulation, and process handling. The commonly used C++
Sr.No | Functions & Description |
---|---|
1 |
abort
It causes the program termination. |
2 |
exit
It causes the program termination with cleaning up. |
3 |
atexit
It registers a function to be called on the exit(). |
4 |
quick_exit
It causes the program termination without completely cleaning up. |
5 |
at_quick_exit
It registers a function to be called on the quick_exit(). |
6 |
_Exit
It is used to terminate the calling process. |
Terminating Program
Let's look at the following example, where we are going to terminate the program immediately.
#include#include int main() { std::cout << "Program Started" << std::endl; if (true) { std::cout << "Exiting Program..." << std::endl; std::exit(0); } std::cout << "Hello" << std::endl; return 0; }
Output
Following is the output of the above code −
Program Started Exiting Program..
Memory Management
Memory management refers to the process of allocating and deallocating of the memory. The commonly used C++
Sr.No | Functions & Description |
---|---|
1 |
calloc
It is used to allocates memory for an array and initializes all to zero. |
2 |
free
It is used to deallocates the previously allocated memory . |
3 |
malloc
It is used to allocate the memory. |
4 |
realloc
It is used to expands or shrinks previously allocated memory. |
Memory Allocation
Consider the following example, where we are going to allocate a block a memory dynamically.
#include#include int main() { int * x = (int * ) std::malloc(4 * sizeof(int)); if (x == nullptr) { std::cerr << "Memory Allocation Failed." << std::endl; return 1; } for (int a = 0; a < 4; ++a) { x[a] = a * 2; std::cout << x[a] << " "; } std::cout << std::endl; std::free(x); return 0; }
Output
If we run the above code it will generate the following output −
0 2 4 6