返回列表 發帖

stringstream 字串串流 (一)

試利用 stringstream 型別,將多個字串串起來,
再利用 str() 函式將物件中的字串帶出來。

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<sstream>
  4. using namespace std;
  5. int main()
  6. {
  7.     stringstream ss;
  8.     string str1="abc";
  9.     string str2="狗咬豬";
  10.     int a=12;
  11.     float b=3.456;
  12.     ss<<str1<<str2<<a<<b<<"...";
  13.     cout<<ss.str()<<endl;
  14.     system("pause");
  15.     return 0;   
  16. }
複製代碼
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<sstream>
  4. using namespace std;
  5. int main()
  6. {
  7.     stringstream ss;
  8.     string str1="abc";
  9.     string str2="狗咬豬";
  10.     int a=12;
  11.     float b=3.456;
  12.     ss<<str1<<str2<<a<<b<<"...";
  13.     string str;
  14.     ss>>str;
  15.     cout<<str<<endl;
  16.     system("pause");
  17.     return 0;
  18. }
複製代碼
Su Wa

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<sstream>
  4. using namespace std;
  5. int main()
  6. {
  7.     stringstream ss;
  8.     string str1="abc";
  9.     string str2="狗咬豬";
  10.     int a=12;
  11.     float b=3.456;
  12.     ss<<str1<<str2<<a<<b<<"...";
  13.     cout<<ss.str()<<endl;
  14.     system("pause");
  15.     return 0;   
  16. }
複製代碼

TOP

本帖最後由 龔品誠 於 2020-8-29 11:54 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<sstream>
  4. using namespace std;
  5. int main()
  6. {
  7.     stringstream ss;
  8.     string str1="abc";
  9.     string str2="狗咬豬";
  10.     int a=12;
  11.     float b=3.456;
  12.     ss<<str1<<str2<<a<<b<<"...";
  13.     string str;
  14.     ss>>str;
  15.     cout<<str<<endl;
  16.     system("pause");
  17.     return 0;
  18. }
複製代碼
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<sstream>
  4. using namespace std;
  5. int main()
  6. {
  7.     stringstream ss;
  8.     string str1="abc";
  9.     string str2="狗咬豬";
  10.     int a=12;
  11.     float b=3.456;
  12.     ss<<str1<<str2<<a<<b<<"...";
  13.     cout<<ss.str()<<endl;
  14.     system("pause");
  15.     return 0;   
  16. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<sstream>
  4. using namespace std;
  5. int main()
  6. {
  7.     stringstream ss;
  8.     string str1="abc";
  9.     string str2="狗咬豬";
  10.     int a=12;
  11.     float b=3.456;
  12.     ss<<str1<<str2<<a<<b<<"...";
  13.     cout<<ss.str()<<endl;
  14.     system("pause");
  15.     return 0;   
  16. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<sstream>
  4. using namespace std;
  5. int main()
  6. {
  7.     stringstream ss;
  8.     string str1="abc";
  9.     string str2="狗咬豬";
  10.     int a=12;
  11.     float b=3.456;
  12.     ss<<str1<<str2<<a<<b<<"...";
  13.     cout<<ss.str()<<endl;
  14.     system("pause");
  15.     return 0;   
  16. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<sstream>
  4. using namespace std;
  5. int main()
  6. {
  7.     stringstream ss;
  8.     string str1="abc";
  9.     string str2="狗咬豬";
  10.     int a=12;
  11.     float b=3.456;
  12.     ss<<str1<<str2<<a<<b<<"...";
  13.     string str;
  14.     ss>>str;
  15.     cout<<str<<endl;
  16.     system("pause");
  17.     return 0;
  18. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<sstream>
  4. using namespace std;
  5. int main()
  6. {
  7.     stringstream ss;
  8.     string str1="abc";
  9.     string str2="狗咬豬";
  10.     int a=12;
  11.     float b=3.456;
  12.     ss<<str1<<str2<<a<<b<<"...";
  13.     cout<<ss.str()<<endl;
  14.     string str;
  15.     ss>>str;
  16.     cout<<str<<endl;
  17.     system("pause");
  18.     return 0;   
  19. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<sstream>
  4. using namespace std;
  5. int main()
  6. {
  7.     stringstream ss;
  8.     string str1="abc";
  9.     string str2="狗咬豬";
  10.     int a=12;
  11.     float b=3.456;
  12.     ss<<str1<<str2<<a<<b<<"...";
  13.     cout<<ss.str()<<endl;
  14.     system("pause");
  15.     return 0;   
  16. }
複製代碼
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<sstream>
  4. using namespace std;
  5. int main()
  6. {
  7.     stringstream ss;
  8.     string str1="abc";
  9.     string str2="狗咬豬";
  10.     int a=12;
  11.     float b=3.456;
  12.     ss<<str1<<str2<<a<<b<<"...";
  13.     string str;
  14.     ss>>str;
  15.     cout<<str<<endl;
  16.     system("pause");
  17.     return 0;
  18. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<sstream>
  4. int main()
  5. {
  6.     stringstream ss;
  7.     string str1="abc";
  8.     string str2="狗咬豬";
  9.     int a=12;
  10.     float b=3.456;
  11.     ss<<str1<<str2<<a<<b<<"..." ;
  12.     cout<<ss.str()<<endl;
  13.      system("pause");
  14.     return 0;   
  15. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<sstream>
  4. int main()
  5. {
  6.     stringstream ss;
  7.     string str1="abc";
  8.     string str2="狗咬豬";
  9.     int a=12;
  10.     float b=3.456;
  11.     ss<<str1<<str2<<a<<b<<"..." ;
  12.     string str;
  13.     ss>>str;
  14.     ss>>str;
  15.    
  16.     cout<<str<<endl;
  17.      system("pause");
  18.     return 0;   
  19. }
複製代碼

TOP

返回列表