返回列表 發帖

C++ 字串輸入 (包含空白)

本帖最後由 tonyh 於 2022-12-8 19:44 編輯
  1. #include<bits/stdc++.h>
  2. using namespace std;

  3. string str;

  4. int main()
  5. {
  6.     cin.tie(0);
  7.     cin.sync_with_stdio(0);

  8.     getline(cin, str);

  9.     cout<<str<<endl;

  10.     cout<<str.size()<<endl;

  11.     cout<<str[1]<<endl;
  12.     cout<<str[3]<<endl;

  13.     return 0;
  14. }
複製代碼
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.     string str;
  8.     cout<<"請輸入一字串(包含空白): ";
  9.     getline(cin,str);
  10.     cout<<"您剛輸入的字串是: "<<str<<endl;
  11.     system("pause");
  12.     return 0;   
  13. }
複製代碼

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define int ll
  5. #define FOR(i,a,b) for(int i=a;i<b;i++)
  6. #define REP(i,n) FOR(i,0,n)
  7. #define REP1(i,n) FOR(i,1,(n)+1)
  8. #define RREP(i,n) for(int i=(n)-1;i>=0;i--)
  9. #define f first
  10. #define s second
  11. #define pb push_back
  12. #define ALL(x) x.begin(),x.end()
  13. #define SZ(x) (int)(x.size())
  14. #define SQ(x) (x)*(x)
  15. #define pii pair<int,int>
  16. #define Graph vector<vector<int>>
  17. #define IOS() cin.sync_with_stdio(0),cin.tie(0),cout.tie(0)
  18. const ll inf=(1ll<<63)-1;
  19. const int maxn=1e4+5;
  20. const ll mod=1e9+7;
  21. string s;
  22. signed main()
  23. {
  24.     IOS();
  25.     getline(cin,s);
  26.     cout<<s<<"\n";
  27.     return 0;
  28. }
複製代碼
Allen

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     cin.tie(0);
  6.     cin.sync_with_stdio(0);
  7.     string str;
  8.     getline(cin,str);
  9.     cout<<"剛剛輸入的字串是"<<str<<endl;
  10.     cout<<str.size()<<" "<<str[1]<<" "<<str[3];
  11.     return 0;
  12. }
複製代碼
hahahahahahahaha

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.     string str;
  8.     cout<<"請輸入一字串(包含空白): ";
  9.     getline(cin,str);
  10.     cout<<"剛輸入的字串是: "<<str<<endl;
  11.     system("pause");
  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;
  8.     cout<<"請輸入一字串(包含空白): ";
  9.     getline(cin,str);
  10.     cout<<"剛輸入的字串是: "<<str<<endl;
  11.     system("pause");
  12.     return 0;   
  13. }
複製代碼
Ivy

TOP

返回列表