连接String与Int(转)
来源:互联网 发布:淘宝单号购买平台 编辑:程序博客网 时间:2024/05/19 14:16
转自:http://blog.csdn.net/cywosp/article/details/8980633
方法一:
template<typename T> static size_t Convert (char buf[], const T value) { static const char digits[] = "9876543210123456789"; static const char* zero = digits + 9; T i = value; char* p = buf; do { int lsd = static_cast<int>(i % 10); i /= 10; *p++ = zero[lsd]; } while (i != 0); if (value < 0) { *p++ = '-'; } *p = '\0'; std::reverse (buf, p); // #include <algorithm> return p - buf; } static inline void IntToString (std::string& out, const int value) { char buf[32]; Convert<int> (buf, value); out.append (buf); }
方法二:
static inline void IntToString (std::string& out, const int value) { char buf[32]; snprintf (buf, sizeof (buf), "%d", value); // snprintf is thread safe #include <stdio.h> out.append (buf); }
方法三:
static inline void IntToString (std::string& out, const int value) { std::strstream ss; // #include <strstream> ss << value; ss >> out; }
方法四:
static inline void IntToString (std::string& out, const int value) { char buf[32]; itoa (value, buf, 10); // #include <stdlib.h> out.append (buf); }
0 0
- 连接String与Int(转)
- 关于javascript的int转String与String转int
- Android String与int类型互转
- 【C++】int与string的互转
- C++ int与string的转化(转)
- Java-int与string类型互转
- 字符串格式化,与int转string
- int与string
- int 与String 互转
- int与string C++
- String与int互转
- string与int转换
- string与int转换
- int与string互转
- js int 与 string
- string与int转换
- [转]int转string string转int
- int转string string转int
- MapReduce 思想解析
- 深入理解JVM之七:静态分派与动态分派
- caj转pdf超简单!
- RecyclerView+Cardview学习探索
- CentOS修改系统时间
- 连接String与Int(转)
- hdoj 第几天?
- c++11,线程池之二--有等待线程池中任务完成功能的线程池
- 朴素贝叶斯算法理解
- 【IOS】IOS OpenCV之HelloWorld
- ContentProvider实现数据共享1
- 滤波电容、去耦电容、旁路电容作用
- 随意细解:UI -- 标签视图控制器
- UIImagePickerController详解