今天写一道题目的时候发现to_string()函数是c11的版本,在老的编译器、oj平台无法通过,查到除了tostring 在老的版本中有很多其他的方法,这里简单记下方便以后使用查询:
(1)利用stringstream:
使用stringstream的时候要注意加#include"sstream"。比如说我要把int类型的23转为string类型,那么我可以这样实现:
int a = 23;
stringstream ss;
ss << a;
string s1 = ss.str();
(2)利用sprintf int->char[]
(3)利用itoa int->char[]
(4)利用to_string