How to use stoi In C++
The stoi() function in C++ converts a string to an integer value. Below is the C++ program to convert char to int using stoi():
C++
// C++ program to convert char // to int using stoi() #include <iostream> #include <string> using namespace std; // Driver code int main() { char s1[] = "45" ; int x = stoi(s1); cout << "The integer value of x : " << x; return 0; } |
Output
The integer value of x : 45
C++ Program For char to int Conversion
Here we will see how to convert char to int using a C++ program. There are 6 ways to convert char to int in C++:
- Using Typecasting.
- Using static_cast.
- Using sscanf().
- Using stoi().
- Using atoi().
- Using string stream.
Let’s discuss each of these methods in detail.
Contact Us