c++ - 如何在 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++
}
解决方案
char c = digit + '0' ;
它会做你的工作。
推荐阅读
- django - Django & intercooler.js : 使用 Intercooler.js 将变量传递给视图
- amazon-web-services - 无法制作 S3 对象,使用 Lambda 从另一个账户上的 S3 存储桶复制,公共
- javascript - 我正在尝试将 JSON 对象发布到 ASP.NET MVC 控制器但得到空 JSON
- python - SMTPAuthenticationError: (535, b'5.7.8 用户名和密码不被接受。了解详情\n5.7.8 https://support.google
- magento - Magento 1.9:获取产品 X 是追加销售的产品
- exception - 为什么要在异常中使用多个捕获?
- windows - windows Jenkins上的groovy命令curl
- hyperledger-fabric - 在 Hyperledger Fabric 中,客户端是向所有订单发送交易还是仅向一个订购者节点发送交易?
- c# - 无法将 int 类型隐式转换为 (namespace.model.class) 类型
- python - 如何用另一个数据框中最接近的日期填充一个数据框中的日期列