試利用 stringstream 型別, 將多個字串串起來,
再利用 str() 函式將物件中的字串帶出來.- #include<iostream>
- #include<sstream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- stringstream ss;
- string str1="abc";
- string str2="狗咬豬";
- ss<<str1<<str2<<"...";
- cout<<ss.str()<<endl;
- system("pause");
- return 0;
- }
複製代碼- #include<iostream>
- #include<sstream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- stringstream ss;
- string str1="abc";
- string str2="狗咬豬";
- string str;
- ss<<str1<<str2<<"...";
- ss>>str;
- cout<<str<<endl;
- system("pause");
- return 0;
- }
複製代碼 |