int main()
{
int arry[5] = { 1, 2, 3, 4, 5 };//一旦申请,不在动态扩增
int * pArry = new int[5];
//容器--动态数组,不用指定大小,会根据数组当前动态调整
std::vector<int> v;//创建动态数组,无需声明大小
v.push_back(1);
v.push_back(2);
v.push_back(3);
v.push_back(4);
v.push_back(5);
//访问数组(1)
for (int i = 0; i < sizeof(arry); i++)
{
//.....
}
//访问数组迭代器模式
std::vector<int>::iterator it;//迭代器
for (it = v.begin; it != v.end(); it++)
{
//.....*it
}
std::vector<int>::iterator it1;
for (std::string str:it1)
{
std::cout << str.c_str() << std::endl;
}
//优点:模板化,统一
std::list<int> v;//创建动态数组,无需声明大小
v.push_back(1);
v.push_back(2);
v.push_back(3);
v.push_back(4);
v.push_back(5);
//auto 类型推导
auto it = v.begin();//自动推导需要消耗性能
while (1)
{
}
return 0;
}