返回列表 發帖

stringstream 字串串流 (一)

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


法1
  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. }
複製代碼
法2
  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

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見
Attention Seeker </3

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

返回列表