1. int sprintf( char *buffer, const char *format [, argument] ... );
<stdio.h>
例如:
1 int ss;
2 char temp[64];
3 string str;
4 ss = 1000;
5 sprintf(temp, "%d", ss);
6 string s(temp);
7 //调用string的方法
8 cout<<s.c_str()<<endl;//1000
9 cout<<s.size()<<endl; //长度为4
2 char temp[64];
3 string str;
4 ss = 1000;
5 sprintf(temp, "%d", ss);
6 string s(temp);
7 //调用string的方法
8 cout<<s.c_str()<<endl;//1000
9 cout<<s.size()<<endl; //长度为4
2.char *_itoa( int value, char *string, int radix );
<stdlib.h>
例如:
1 char buffer[20];
2 int i = 3445;
3 _itoa( i, buffer, 10 );
4 string s(buffer);
2 int i = 3445;
3 _itoa( i, buffer, 10 );
4 string s(buffer);
3. stringstream( )
<sstream.h>
例如:
1 int hello=4;
2 stringstream ss;
3 ss<<hello;
4 string s=ss.str();
5 //调用string的方法
6 cout<<s.c_str()<<endl;
2 stringstream ss;
3 ss<<hello;
4 string s=ss.str();
5 //调用string的方法
6 cout<<s.c_str()<<endl;
转自http://www.cnblogs.com/lshguang89/archive/2008/06/09/1216334.html