Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert an integer to a character in C++

Say I have an integer and I want to convert it to a character? What methods are available or should I use in C++? For example, refer to the given code below

      #include <bits/stdc++.h>
      using namespace std;
      int main
        {
            int i = 1;
           // Say I want to convert 1 to a char  '1';
           // How do I achieve the following in C++
        }
like image 879
Kaushik Avatar asked Oct 20 '25 13:10

Kaushik


1 Answers

char c = digit + '0' ;

It will do your work.

like image 65
iamdhavalparmar Avatar answered Oct 23 '25 04:10

iamdhavalparmar