将整型数据转换为string类型
来源:互联网 发布:零基础学算法pdf 编辑:程序博客网 时间:2024/05/16 18:10
将整型数据转换为string类型
在进行代码数据处理的时候,遇到数据类型转换的问题。因为string类型重载了+等操作符,处理数据起来比较方便,但是有些时候需要将其他类型的数据加到string类型中,这就出现了其他类型转换为string类型的问题。
要实现Int 等类型转换为string类型,首先要用系统函数ltoa 、itoa等转换为char* ,然后在转换为string中。
char c[20];
string buf,buf2;
buf = ltoa(23,c,10);
buf2 = itoa(32,c,10);
cout<<buf<<" "<<buf2<<endl;
char * __cdecl ltoa(__in long _Val, __out_z char * _DstBuf, __in int _Radix);
char * __cdecl itoa(__in int _Val, __out_z char * _DstBuf, __in int _Radix);
在网上还有很多其他方法,比如有stringstram的方式。
其中char* 、string、Cstring等区别可参考文章http://www.360doc.com/content/15/0803/19/21172899_489295148.shtml
0 0
- 将整型数据转换为string类型
- javascript 将字符串类型转换为整型
- QT 整型数据转换为字符串类型
- 将内置类型转换为string类型
- 将String类型转换为Int类型
- 07-String类型转换为整型(字符串处理)
- 高效的将整型类型转换为字符串的方法
- “无法将类型"string"转换为"char"”?
- 将int转换为string类型
- 如何将string转换为Date类型
- 将字符串数据转换为其他类型
- js将时间由long类型转换为string类型
- 如何将 String类型 转换为日期格式 Date类型
- java 将Date类型转换为String类型
- C++中如何将char类型转换为String 类型
- 将postData数据转换为Hashtable<String, String[]>
- 请问如何将Date类型转换为String类型????或String类型转换为Date类型??Access数据库...
- 将字符型转换为整型
- 基本数据类型
- AFNetwork 作用和用法详解
- android 获取系统时间的几种方法
- strange behavior when using linux shell
- C语言之关键字const
- 将整型数据转换为string类型
- Java的值传递
- spring调用存储过程
- c++ builder使用过程中,记录的bug
- [LeetCode303] Range Sum Query - Immutable
- Mybatis插入多条相同记录
- cocos2d游戏接入admob,解决,@import GoogleMobileAds 错误的方法
- plsql 连接不上 登陆不了 tnsnames.ora 问题
- 把Eclipse项目迁移到AndroidStudio