int转string
#include<string>
#include<sstream>
#include<iostream>
using namespace std;
int main()
{
stringstream stream;
string result;
long long i=1000000000000000000;
stream<<i; //将int输入流
stream>>result;//从stream中抽取前面插入的int值
cout<<result<<endl;
}
string到int的转换
#include<string>
#include<sstream>
#include<iostream>
using namespace std;
int main()
{
stringstream stream;
string result="1000000000000000000";
long long i;
stream<<result; //将int输入流
stream>>i;//从stream中抽取前面插入的int值
cout<<i<<endl;
}
#include <sstream>
#include <iostream>
int main()
{
std::stringstream stream;
char result[8] ;
stream << 8888; //向stream中插入8888
stream >> result; //抽取stream中的值到result
std::cout << result << std::endl; // 屏幕显示 "8888"
}
再进行多次转换的时候,必须调用stringstream的成员函数clear().