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

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

 1  如何将int,double转std::string? (C/C++) (template) /* 
 2 如何将int,double转std::string? (C/C++) (template)(C) OOMusou 2006 http://oomusou.cnblogs.com
 3 如何将int,double转std::string? (C/C++) (template)
 4 如何将int,double转std::string? (C/C++) (template)Filename    : ArrayToVectorByConstructor.cpp
 5 如何将int,double转std::string? (C/C++) (template)Compiler    : Visual C++ 8.0
 6 如何将int,double转std::string? (C/C++) (template)Description : Demo how to convert any type to string.
 7 如何将int,double转std::string? (C/C++) (template)Release     : 11/18/2006
 8 如何将int,double转std::string? (C/C++) (template)*/

 9  如何将int,double转std::string? (C/C++) (template)#include  < iostream >
10  如何将int,double转std::string? (C/C++) (template)#include  < sstream >
11  如何将int,double转std::string? (C/C++) (template)#include  < string >
12  如何将int,double转std::string? (C/C++) (template)
13  如何将int,double转std::string? (C/C++) (template)template  < class  T >  
14  如何将int,double转std::string? (C/C++) (template)std:: string  ConvertToString(T);
15  如何将int,double转std::string? (C/C++) (template)
16  如何将int,double转std::string? (C/C++) (template) int  main()  {
17 如何将int,double转std::string? (C/C++) (template)  std::string s;
18 如何将int,double转std::string? (C/C++) (template)
19 如何将int,double转std::string? (C/C++) (template)  // Convert int to std::string
20 如何将int,double转std::string? (C/C++) (template)  int i = 123;
21 如何将int,double转std::string? (C/C++) (template)  s = ConvertToString(i);
22 如何将int,double转std::string? (C/C++) (template)  std::cout << s << std::endl;
23 如何将int,double转std::string? (C/C++) (template)
24 如何将int,double转std::string? (C/C++) (template)  // Convert double to std::string
25 如何将int,double转std::string? (C/C++) (template)  double d = 123.123
26 如何将int,double转std::string? (C/C++) (template)  s = ConvertToString(d);
27 如何将int,double转std::string? (C/C++) (template)  std::cout << s << std::endl;
28 如何将int,double转std::string? (C/C++) (template)
29 如何将int,double转std::string? (C/C++) (template)  return 0;
30 如何将int,double转std::string? (C/C++) (template)}

31  如何将int,double转std::string? (C/C++) (template)
32  如何将int,double转std::string? (C/C++) (template)template  < class  T >  
33  如何将int,double转std::string? (C/C++) (template)std:: string  ConvertToString(T value)  {
34 如何将int,double转std::string? (C/C++) (template)  std::stringstream ss;
35 如何将int,double转std::string? (C/C++) (template)  ss << value;
36 如何将int,double转std::string? (C/C++) (template)  return ss.str();
37 如何将int,double转std::string? (C/C++) (template)}

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

你可能感兴趣的:(template)