返回列表 發帖

2025/3/14 課堂重點(昀杰)

  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<sstream>
  2. using namespace std;
  3. int main()
  4. {
  5.     stringstream ss;
  6.     string s,d="123 42 13 56 8 67 7";
  7.     ss<<d;
  8.     while(ss>>s)
  9.     {
  10.         cout<<s<<endl;
  11.     }
  12.     return 0;
  13. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.     string str="012 34  567  89";
  8.     cout<<str.substr(5)<<endl;
  9.     cout<<str.substr(2)<<endl;
  10.     cout<<str.substr(3,3)<<endl;
  11.     cout<<str.substr(7,1)<<endl;
  12.     system("pause");
  13.     return 0;
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<algorithm>
  4. using namespace std;
  5. int main()
  6. {
  7.     string str="Hello World!";
  8.     cout<<str<<endl;
  9.     cout<<<<str.find('H')<<endl;
  10.     cout<<<<str.rfind('o')<<endl;
  11.     cout<<str.find("llo")<<endl;
  12.     cout<<str.find('l', 4)<<endl;
  13.     int res=str.find('a');
  14.     cout<<res<<endl;

  15.     return 0;
  16. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. #include<algorithm>
  5. using namespace std;
  6. int main()
  7. {
  8.     string str1="honolulu";
  9.     cout<<str1.replace(1,3,"a")<<endl;  //halulu

  10.     string str2="honolulu";
  11.     cout<<str2.replace(str2.find("u"),1,"a")<<endl;  //honolalu

  12.     string str3="honolulu";
  13.     replace(str3.begin(),str3.end(),'u','a');
  14.     cout<<str3<<endl;     //honolala

  15.     system("pause");
  16.     return 0;
  17. }
複製代碼

TOP

2 + 3 * 4

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<sstream>
  4. using namespace std;
  5. int main()
  6. {
  7.     string s="123.45.6789";
  8.     stringstream ss;
  9.     int f=0;
  10.     while(true)
  11.     {
  12.         f=s.find(".");
  13.         if(f<0)
  14.         {
  15.            break;
  16.         }
  17.         s.replace(f,1," ");
  18.     }
  19.     ss<<s;
  20.     while(ss>>s)
  21.     {
  22.         cout<<s<<endl;
  23.     }
  24.     system("pause");
  25.     return 0;
  26. }
複製代碼

TOP

返回列表