c++ stringstream 实现字符串与int之间的转换
#include <iostream> #include <sstream> using namespace std; int main() { //string转int string str="10"; int num; stringstream ss; ss<<str; ss>>num; cout<<num+1; ss.clear();//将读写状态重置 ss.str("");//将内容置空 //int转string int num2=100; string str2; ss<<num2; ss>>str2; str2[0]='d'; cout<<str2;
ss.clear();//将读写状态重置
ss.str("");//将内容置空
//int转string
int num3=100;
ss << num3;
cout<<ss.str();
}