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

TOP

本帖最後由 孫嘉駿 於 2020-5-15 20:30 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string str;
  7.     int x;
  8.     cout<<"請輸入一任意英文字串: ";
  9.     getline(cin,str);
  10.     cout<<"想要電腦幫你抓出第幾個字? ";
  11.     cin>>x;
  12.     cout<<"字串的第"<<x<<"個字母為: "<<str[x-1]<<endl;
  13.     system("pause");
  14.     return 0;   
  15. }
複製代碼

TOP

返回列表