How to use static_cast In C++
The integer can be converted to a character using the static_cast function. Below is the C++ program to convert int to char using static_cast:
C++
// C++ program to convert // int to char using static_cast #include <iostream> using namespace std; // Driver code int main() { int N = 65; char c = static_cast < char >(N); cout << c; return 0; } |
Output
A
C++ Program For int to char Conversion
In this article, we will learn how to convert int to char in C++. For this conversion, there are 5 ways as follows:
- Using typecasting.
- Using static_cast.
- Using sprintf().
- Using to_string() and c_str().
- Using stringstream.
Let’s start by discussing each of these methods in detail.
Examples:
Input: N = 65
Output: AInput: N = 97
Output: a
Contact Us