6.CPP风格数组
//数组初始化
1 #include <iostream> 2 using namespace std; 3 4 5 6 void main() 7 { 8 //C int a[5] = { 1,2,3,4,5 }; 9 //C++ int a[5]{ 1,2,3,4,5 }; 10 11 //C int *p = new int[5]{ 1,2,3,4,5 }; 12 //C++ int *p2(new int[5] { 1, 2, 3, 4, 5 }); 13 14 15 cin.get(); 16 }
- C++风格数组
1 #include <iostream> 2 #include <array> 3 using namespace std; 4 5 6 7 void main() 8 { 9 //一维数组 10 //在栈上分配内存 11 //前面是元素类型 12 array<int, 10>myint = { 1,2,3,4,5,6,7,8,9,10 };//CPP分个 13 /*for (auto i : myint) 14 { 15 cout << i << endl; 16 }*/ 17 18 array <array<int, 10>, 3>myint2{ myint,myint,myint }; 19 20 for (auto i : myint2) 21 { 22 for (auto j : i) 23 { 24 cout << j << " "; 25 } 26 cout << endl; 27 } 28 cin.get(); 29 }