流云飞飞

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
#include <cstdlib>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
const int MAX = 100;
/*frist method*/
inline void numToString0(int value)
{
    string str;
    char buf[MAX];
    
    sprintf(buf, "%d", value);
    str = buf;
    
    cout << str << endl;
}
/*second method*/
inline void numToString1(int value)
{
    stringstream ss;
    string str;
    
    ss << value;
    ss >> str;
    
    cout << str << endl;
}
/*third method*/
inline void numToString2(int value)
{
    ostringstream os;
    os << value;
    
    cout << os.str() << endl;
}
int main(int argc, char *argv[])
{
    int value;
    cin >> value;
    
    numToString0(value);
    numToString1(value);
    numToString2(value);
    
    /*string to numeric*/
    stringstream ss;
    string str("123456778");
    int i;
    ss << str;
    ss >> i;
    cout << i << endl;
    /*end*/
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

 

posted on 2013-05-14 14:19  流云飞飞  阅读(634)  评论(0)    收藏  举报