int,float,double 与 string 互转
sstream
- istringstream
string d = "44.567";
float f;
istringstream in(d);
in>>f;
cout<<f<<endl;
- ostringstream
float d = 123.668;
ostringstream out;
out<<d;
cout<<out.str()<<endl;
to_string(), stoi(), stol(), stoll(), stof(), stod(), stold(), stoul(),stoull()
需要c++11支持
当有时候不支持c++11时可以使用sprintf, sscanf,参考链接:
http://www.jb51.net/article/39699.htm