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 *_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); 


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; 

 

 

转自http://www.cnblogs.com/lshguang89/archive/2008/06/09/1216334.html

相关文章:

  • 2021-12-23
  • 2021-10-10
  • 2022-12-23
  • 2021-12-22
  • 2021-09-23
  • 2022-12-23
  • 2021-11-20
猜你喜欢
  • 2021-09-24
  • 2022-12-23
  • 2022-02-17
  • 2021-12-13
  • 2022-12-23
  • 2021-06-22
  • 2021-10-06
相关资源
相似解决方案