返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #8105同步于 2008/6/3
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
C++中如何将int型转化为string型?
win520
2008/6/3镜像同步8 回复
订阅后,新回复会通过你的通知中心匿名送达。
8 条回复
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
template <class T>
string toString(const T& s) {
ostringstream os;
os << s;
return os.str();
}
int main(){
int a = 123456;
string b = toString(a);
cout<<b<<endl;
return 0;
}
string(sprintf("%s", ..));
【 在 NWN2 (Neverwinter Nights 2) 的大作中提到: 】
: sprintf,得到char*,然后创建string