c++实现各类型值转换为string

c++ stl中的stringstream可以方便的将各种类型值转换成string。

头文件 #include <sstream>

样例:

#include <iostream>
#include <sstream>

using namespace std;

int main()
{
	int a = 10;
	long long b = 11;
	string c = "12";
	double d = 0.13;
	short e = 14;
	char f = 'o';
	stringstream s;
	s<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<' '<<f;
	cout<<s.str()<<endl;
	return 0;
}


猜你喜欢

转载自blog.csdn.net/vocaloid01/article/details/79950441