Board logo

標題: 清空 stringstream [打印本頁]

作者: tonyh    時間: 2018-8-27 20:13     標題: 清空 stringstream

ss.str("");
ss.clear();

  1. #include<iostream>
  2. #include<sstream>
  3. #include<cstdlib>
  4. using namespace std;
  5. int main()
  6. {
  7.     stringstream ss;
  8.     string str1="123",str2="456",str3,str4;
  9.     ss<<str1;
  10.     cout<<"ss: "<<ss.str()<<endl;
  11.     ss>>str3;
  12.     cout<<"str3: "<<str3<<endl;
  13.     ss.str("");
  14.     ss.clear();
  15.     ss<<str2;
  16.     cout<<"ss: "<<ss.str()<<endl;
  17.     ss>>str4;
  18.     cout<<"str4: "<<str4<<endl;
  19.     system("pause");     
  20.     return 0;   
  21. }
複製代碼

作者: 洪翊展    時間: 2018-8-27 20:44

  1. #include<iostream>
  2. #include<sstream>
  3. #include<cstdlib>
  4. using namespace std;
  5. int main()
  6. {
  7.     stringstream ss;
  8.     string str1="123",str2="456",str3,str4;
  9.     ss<<str1;
  10.     cout<<"ss: "<<ss.str()<<endl;
  11.     ss>>str3;
  12.     cout<<"str3: "<<str3<<endl;
  13.     ss.str("");
  14.     ss.clear();
  15.     ss<<str2;
  16.     cout<<"ss: "<<ss.str()<<endl;
  17.     ss>>str4;
  18.     cout<<"str4: "<<str4<<endl;
  19.     system("pause");     
  20.     return 0;   
  21. }
複製代碼

作者: 李沛昂    時間: 2018-9-2 20:17

  1. #include<iostream>
  2. #include<sstream>
  3. #include<cstdlib>
  4. using namespace std;
  5. int main()
  6. {
  7.     stringstream ss;
  8.     string str1="123",str2="456",str3,str4;
  9.     ss<<str1;
  10.     cout<<"ss: "<<ss.str()<<endl;
  11.     ss>>str3;
  12.     cout<<"str3: "<<str3<<endl;
  13.     ss.str("");
  14.     ss.clear();
  15.     ss<<str2;
  16.     cout<<"ss: "<<ss.str()<<endl;
  17.     ss>>str4;
  18.     cout<<"str4: "<<str4<<endl;
  19.     system("pause");     
  20.     return 0;   
  21. }
複製代碼

作者: 戴嘉禾    時間: 2018-9-3 18:42

  1. #include<iostream>
  2. #include<sstream>
  3. #include<cstdlib>
  4. using namespace std;
  5. int main()
  6. {
  7.     stringstream ss;
  8.     string str1="123",str2="456",str3,str4;
  9.     ss<<str1;
  10.     cout<<"ss: "<<ss.str()<<endl;
  11.     ss>>str3;
  12.     cout<<"str3: "<<str3<<endl;
  13.     ss.str("");
  14.     ss.clear();
  15.     ss<<str2;
  16.     cout<<"ss: "<<ss.str()<<endl;
  17.     ss>>str4;
  18.     cout<<"str4: "<<str4<<endl;
  19.     system("pause");     
  20.     return 0;   
  21. }
複製代碼

作者: 啓銓    時間: 2018-11-26 19:31

  1. #include<iostream>
  2. #include<sstream>
  3. #include<cstdlib>
  4. using namespace std;
  5. int main()
  6. {
  7.     stringstream ss;
  8.     string str1="123",str2="456",str3,str4;
  9.     ss<<str1;
  10.     cout<<"ss: "<<ss.str()<<endl;
  11.     ss>>str3;
  12.     cout<<"str3: "<<str3<<endl;
  13.     ss.str("");
  14.     ss.clear();
  15.     ss<<str2;
  16.     cout<<"ss: "<<ss.str()<<endl;
  17.     ss>>str4;
  18.     cout<<"str4: "<<str4<<endl;
  19.     system("pause");     
  20.     return 0;   
  21. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2