Vulkan

使用动态数组

#include <iostream>
#include <vector>
using namespace std;
void Test(vector<int> & ve)
{
int *tem=new int[ve.size()];
for (int j=0;j<ve.size();j++)
{
tem[j]=ve[j];
}
for (int k=0;k<ve.size();k++)
{
cout<<tem[k]<<endl;

}

/***最后重要的是别忘了将动态创造的空间释放掉,语句是:delete [] tem;  ***/

/***‘[ ]’表明该指针是指向的自由存储区的数组,而非单个对象。如果遗漏了空方括号,编译器将无法发现这个错误,将导致程序在运行时出错***/

delete [] tem; 

}
int main()
{
vector<int>vev;
for (int i=0;i<10;i++)
{
vev.push_back(i*2+1);
}
Test(vev);
return 0;
}

posted on 2012-07-13 10:35  Vulkan  阅读(133)  评论(0编辑  收藏  举报

导航