#include <iostream>
#include<vector>
using namespace std;
int main()
{
const int seq_cnt=6;
vector<int> Fiboncci,Lucas,Pell,Triangular,Square,Pentagonal;
Fiboncci={1,1,2,3,5,8,13,21};
Lucas={1,3,4,7,11,18,29,47};
Pell={1,2,5,12,29,70,169,408};
Triangular={1,3,6,10,15,21,28,36};
Square={1,4,916,25,36,49,64};
Pentagonal={1,5,12,22,35,51,70,92};
vector<int> *current_vec=0;
vector<int> *seq_addrs[seq_cnt]={&Fiboncci,&Lucas,&Pell,&Triangular,&Square,&Pentagonal};
//seq_addrs为一个指针数组,大小为seq_cnt 每个指针都指向vector<int>对象
//seq_addrs为一个array 元素类型为vector<int> *
//seq_addrs[0]所持有的值是Fiboncci vector的地址
for (int i=0;i<seq_cnt;++i) {
current_vec=seq_addrs[i];
vector<int> vec=*current_vec;
for (int j=0;j<current_vec->size();j++) {
//cout<<(*current_vec);
cout<<(*current_vec)[j]<<"::";//读取每一个vector<int>的元素
}
cout<<endl;
}
cout << "Hello World!" << endl;
return 0;
}
1、C++指针数组灵活使用
最新推荐文章于 2024-11-09 20:38:27 发布