类似于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; }
评论
相当痛苦,无法处理尖括号
我还是写成文档上传算了
使用标准C++库的话,就是这样
#include<string>
#include<sstream>
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;
}