C++ is a Object-Oriented Programming language that is vastly around the globe becuase of its speed.
C++ when implemented directly on hardware, produce very swift results.
Many libraries in languages like python are written in C++ for faster implementations.
Today we will look at some libraries in C++ that are a must know and makes our work easy.
1. iostream.h
iostream stands for Input Output Stream and handles all the I/O operations to and from user.
It is the very first library that is taught in schools or coding bootcamps for C++.
It has basic functions like cout and cin which are used for I/O.
cout handles the output stream, printing data on screen or any other output device.
cin handles the input stream, accepting input from user via keyboard or any other input device.
Both have a respective buffer attached to them.
To know more, refer here
2. string.h
There are two ways in C++ to handle character sequence or Strings in C++, through C-style strings or through String STL.
C-style strings were natively used in C, and were inherited from there in C++.
String handling via C-string becomes quite difiicult as the complexity of the program increases.
That's why we use strings as a STL.
To acheive this we use syntax as follows
#include <iostream>
#include <string>
int main()
{
string str; //declaring a string is this easy
cin >> str;
cout << str;
return 0;
}
This library makes operations like reversing a string, concatenation, and many more very easy (merely a function call).
I'll write more about how to use these functions with syntax in my next article.
To know more about strings, refer here
3. math.h
This header file declares a set of functions to compute common mathematical operations and transformations.
Many mathematical functions like
-
computing square root
sqrt()
-
ceil value of a number
ceil()
-
log value of a number
log2()
and many more
are defined in this library and can be accessed by a simple function call.
Let's see a sample program to undrstand better.
#include <iostream>
#include <math.h>
int main()
{
int n;
cin >> n;
cout << sqrt(n);
return 0;
}
displays square root of entered number.
To know more, refer
4. regex
Regular expressions are a standardized way to express patterns to be matched against sequences of characters.
The standard C++ library provides support for regular expressions in the header through a series of operations.
This library is available with C++ 11.
Baisc regular expression operation like pattern matching and text searching are available.
A pretty handy library.