C++ 入門指南 4.01
練習 15.5 參考程式 - 練習標準程式庫的 array
// 引入標準程式庫中相關的輸入、輸出程式
#include <iostream>
// 引入標準程式庫中的 array
#include <array>
// cout 為 std 中的輸出物件
using std::cout;
// endl 為 std 中的斷行符號
using std::endl;
// array 為 std 中的陣列型態
using std::array;
int main(void) {
// 宣告建立整數 array
array<int, 5> a = {1, 2, 6, 4, 5};
// 印出陣列中的第一個元素
cout << a.front() << endl;
// 印出陣列中的最後一個元素
cout << a.back() << endl;
// 最後回傳 0 給作業系統
return 0;
}
/* 《程式語言教學誌》的範例程式
http://kaiching.org/
檔名:exercise1505.cxx
編譯:g++ exercise1505.cxx
執行:./a.out
功能:C++入門指南單元十五的練習
作者:張凱慶 */
回到練習題目