array
数组初始化 int *p =(int[]){1,3,3,4,5});//C风格 int a[5]{1,2,3,4,5};//栈上 int *p(new int[5]{1,3,3,4,5});//堆上
#include <iostream>
#include <array>
int main(int argc, const char * argv[])
{
int *p = new int[5]{5, 4, 3, 2, 1};
for (int i =0; i<5; i++) {
cout<<p[i];
}
cout<<endl;
int a[5]{5, 4, 3, 2, 1};
for (int i = 0; i<5; i++) {
cout<<a[i];
}
cout<<endl;
for(auto i : a){
cout<< i;
}
cout<<endl;
array<int, 10> cppArray {10, 9, 8, 7, 6, 5,4,3,2,1};
for (auto i : cppArray){
cout<<i<<" "<<&cppArray[i]<<endl;
}
cout<<endl;
array<int, 10> cppArray1 {10, 9, 8, 7, 6, 5,4,3,2,1};
array<int, 10> cppArray2 {10, 9, 8, 7, 6, 5,4,3,2,1};
array<int, 10> cppArray3 {10, 9, 8, 7, 6, 5,4,3,2,1};
array<array<int, 10>, 3> mutiArray {cppArray1, cppArray2, cppArray3};
for(auto j : mutiArray) {
for(auto i : j){
cout<< i << " ";
}
cout <<endl;
}
cout<<endl<<endl;
array<array<int, 10>, 3> mutiArray1 {cppArray1, cppArray2, cppArray3};
array<array<int, 10>, 3> mutiArray2 {cppArray1, cppArray2, cppArray3};
array<array<int, 10>, 3> mutiArray3 {cppArray1, cppArray2, cppArray3};
array<array<array<int, 10>, 3>, 3> muti3Array {mutiArray1, mutiArray2, mutiArray3};
for(auto j : muti3Array) {
for(auto i : j){
for(auto h : i){
cout<< h << " ";
}
cout <<endl;
}
cout <<endl;
}
return 0;
}
tuple多元数组
多元数组无法用auto遍历
#include <tuple>
char a = 'x';
short b = 13;
int c = 125;
double d = 3.14;
char *p("poniter");
tuple<char, short, int, double, char*> mytuple();
cout << get<0>(mytuple)<<endl<<get<1>(mytuple)<<endl<<get<2>(mytuple);
|