要将字符转换为整数 [英] TO convert a character into integer
本文介绍了要将字符转换为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何将一个角色转换为整数
char a [40]
我对此的输入可能像21466845687552
现在我想要访问每个元素并希望将其转换为整数然后应用aritmatic操作我可以这样做吗?
解决方案
我们如何将一个字符转换为整数
char a [40]
我对此的输入可能像21466845687552
现在我想访问每个元素并希望将其转换为整数然后应用aritmatic操作我可以这样做吗???????
使用函数atoi()
这会将字符转换为整数。
问候,
Girish。
我尽量避免使用atoi()。在C ++中,使用字符串流更好(在我看来)。试试这个:
展开 | 选择 | Wrap | 行号
我认为OP表示数组的每个元素都被转换为整数。
如果是这种情况,你要做的就是:
展开 | 选择 | Wrap | 行号< /跨度>
How can we convert a character into integer
char a[40]
my input to this may be like 21466845687552
now i want to access each element and want to convert it into integer and then apply aritmatic operation can i do this???????解决方案How can we convert a character into integer
char a[40]
my input to this may be like 21466845687552
now i want to access each element and want to convert it into integer and then apply aritmatic operation can i do this???????Use function atoi()
This will convert character to integer.
Regards,
Girish.
I try to avoid atoi(). In C++, it is better (in my opinion) to use stringstreams. Try this:
Expand|Select|Wrap|Line Numbers
I think the OP said each element of the array had top be converted to an integer.
If that''s the case, all you do is:
Expand|Select|Wrap|Line Numbers
这篇关于要将字符转换为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文登录 关闭
扫码关注1秒登录发送“验证码”获取 | 15天全站免登陆