C++ 入門指南 4.01

練習 24.9 參考程式 - 練習標準程式庫的 string

// 引入標準程式庫中相關的輸入、輸出程式
#include <iostream>
// 引入標準程式庫中相關的 string
#include <string>

// cout 為 std 中的輸出物件
using std::cout;
// endl 為 std 中的斷行符號
using std::endl;
// string 為 std 中字串型態
using std::string;

int main(void) {
    // 設定字串
    string s = "Free your mind.";

    // 判斷字串開頭
    cout << s.ends_with("mind") << endl;
    cout << s.ends_with(".") << endl;

    // 最後回傳 0 給作業系統
    return 0;
}

/* 《程式語言教學誌》的範例程式
   http://kaiching.org/
   檔名:exercise2409.cxx
   編譯:g++ exercise2409.cxx -std=c++20
   執行:./a.out
   功能:C++入門指南單元二十四的練習
   作者:張凱慶 */
回到練習題目

上一頁 練習 24.8 參考程式 - 練習標準程式庫的 string
回 C++ 入門指南 4.01 目錄
下一頁 練習 24.10 參考程式 - 練習標準程式庫的 string
回 C++ 教材
回程式語言教材首頁