- #include<iostream>
- #include<sstream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- stringstream ss;
- int a=123;
- string str;
- cout<<"整數型態: "<<a<<endl;
- ss<<a;
- ss>>str;
- cout<<"字串型態: "<<str<<endl;
- system("pause");
- return 0;
- }
複製代碼- #include<iostream>
- #include<sstream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- stringstream ss;
- int a=123;
- string str;
- cout<<"整數型態: "<<a+456<<endl;
- ss<<a;
- ss>>str;
- cout<<"字串型態: "<<str+"456"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |