返回列表 發帖

字串處理 (二) - 字串輸入 1

本帖最後由 許婷芳 於 2020-5-15 20:52 編輯

getline() 用法:接收一個字符串,可以接收空格並輸出。
需加上 #include<string>
  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

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

此帖僅作者可見

TOP

返回列表