您的位置:首页 > 编程语言 > C语言/C++

(原創) 如何将int,double转std::string? (C/C++) (template)

2006-10-10 21:47 519 查看
std::string为library type,而int、double为built-in type,两者无法互转,这里使用function template的方式将int转std::string,将double转std:string。

1#include <iostream>

10#include <sstream>

11#include <string>

12

13template <class T>

14std::string ConvertToString(T);

15

16

32template <class T>

33std::string ConvertToString(T value) {

34 std::stringstream ss;

35 ss << value;

36 return ss.str();

37}

See Also

(原創) 如何将std::string转int,double? (C/C++) (template)

(原創) 如何將int轉string? (C/C++)

(筆記) 如何將int,double轉字串? (C/C++) (C)

Reference

Bertel Brander, Midgaard, http://home20.inet.tele.dk/midgaard/tipc20050107.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: