c++ int to string(整型到字符串)
2008-09-09 21:41
381 查看
1. int sprintf( char *buffer, const char *format [, argument] ... );
<stdio.h>
例如:
int ss;
char temp[64];
string str;
ss = 1000;
sprintf(temp, "%d", ss);
string s(temp);
//调用string的方法
cout<<s.c_str()<<endl;//1000
cout<<s.size()<<endl; //长度为4
2.char *_itoa( int value, char *string, int radix );
<stdlib.h>
例如:
char buffer[20];
int i = 3445;
_itoa( i, buffer, 10 );
string s(buffer);
3. stringstream( )
<sstream.h>
例如:
int hello=4;
stringstream ss;
ss<<hello;
string s=ss.str();
//调用string的方法
cout<<s.c_str()<<endl;
<stdio.h>
例如:
int ss;
char temp[64];
string str;
ss = 1000;
sprintf(temp, "%d", ss);
string s(temp);
//调用string的方法
cout<<s.c_str()<<endl;//1000
cout<<s.size()<<endl; //长度为4
2.char *_itoa( int value, char *string, int radix );
<stdlib.h>
例如:
char buffer[20];
int i = 3445;
_itoa( i, buffer, 10 );
string s(buffer);
3. stringstream( )
<sstream.h>
例如:
int hello=4;
stringstream ss;
ss<<hello;
string s=ss.str();
//调用string的方法
cout<<s.c_str()<<endl;
相关文章推荐
- c++ int to string(整型到字符串)
- c++ int to string(整型到字符串)
- c++ int to string(整型到字符串)
- c++ int to string 整型到字符串
- c++ int to string 整型到字符串
- int to string 整型转化为字符串( C语言接口与实现:创建可重用软件的技术)
- [C++]LeetCode 8:String to Integer (atoi)(字符串转int)
- 整型转字符串(convert int to char)优化实践——一个意外的BUG
- 剑指offer--字符串转数字 string to int
- SQL字符串转为Int表函数StringToIntArray
- [C++基础] int to string
- C++ - 字符串(string)和数字(int、float...)互相转换
- LeetCode 08:string to int(atoi)(C++实现)
- 在c++Builder中使用boost正则表达式实现的查找double和int类型的字符串,并实现StringToInteger和StringToDouble函数
- C++中字符串string和整形int的转化
- leetcode——String to Integer (atoi) 字符串转换为整型数(AC)
- c++ int to string
- LeetCode 8. String to Integer (atoi) C++ --字符串转为数字,包含正负号、空格、字母、数字等字符
- 字符串阵列String[]转换为整型阵列Int[]
- 【C++】int转换为string的两种方法(to_string、字符串流)