当前位置

boost::lexical_cast

主标签

类似于atoi , itoa之类的函数:

用法:

#include <boost/lexical_cast.hpp>
lexical_cast(要转换的内容);

实例:

#include <string>
#include <boost/lexical_cast.hpp>
using namespace std;

int main()
{
        using boost::lexical_cast;
        string str = "1000";
        int    num = 90;

        int    a = lexical_cast<int>( str);
        string s = lexical_cast<string>(num);

        return 0;
}

评论

我还是写成文档上传算了

#include&ltstring&gt

#include&ltsstream&gt

using namespace std;

int main()

{

string str = "1000";

int num = 90;

ostringstream oss;

istringstream iss(str);

int a;

string s;

iss >> a;

oss
s = oss.str();

return 0;

}