#include using namespace std; int main() { // 申明 cout << "Declaration" << endl; string cars[4] = {"Volvo", "BMW", "Ford", "Mazda"}; cout << cars[0] << endl; // 修改 cout << "Modificaiton" << endl; cars[0] = "Opel"; cout << cars[0] << endl; // 循环 cout << "for loop" << endl; string vehicles[5] = {"Volvo", "BMW", "Ford", "Mazda", "Tesla"}; for (int i = 0; i < 5; i++) { cout << vehicles[i] << endl; } // 循环2 cout << "for each loop" << endl; int myNumbers[5] = {10, 20, 30, 40, 50}; for (int i : myNumbers) { cout << i << endl; } // 省略大小 cout << "Omit size during declaration" << endl; string pc[3] = {"Lenovo", "HP", "Dell"}; // Also three arrays for (int i = 0; i < sizeof(pc) / sizeof(string); i++) { cout << pc[i] << endl; } // 获取大小 cout << "Get size" << endl; cout << sizeof(pc) / sizeof(string) << endl; // 多维数组 cout << "Loop multi-dimension" << endl; string letters[2][4] = { { "A", "B", "C", "D" }, { "E", "F", "G", "H" } }; cout << letters[0][2] << endl; // 循环多维数组 for (int i = 0; i < 2; i++) { for (int j = 0; j < 4; j++) { cout << letters[i][j] << " "; } cout << endl; } }