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