首页 > 解决方案 > 如何在 C++ 中将整数转换为字符

问题描述

假设我有一个整数,我想将它转换为一个字符?在 C++ 中可以使用或应该使用哪些方法?例如,参考下面给定的代码

      #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++
        }

标签: c++type-conversioncharinteger

解决方案


char c = digit + '0' ;

它会做你的工作。


推荐阅读