我有兩個問題:如何使用矢量打印數值,以及如何將數值添加到數組的末尾?
1-如何打印下面所述代碼的值?
#include <iostream>
#include <list>
using namespace std;
int main()
{
int i;
list<int> a;
for(i; i<5; i++)
{
a.push_back(i);
}
system("pause");
return 0;
}
2-如何將新元素添加到整數數組?例如,我有一個數組這樣的:
int *a;
int size = 3
a = new int [size];
a[0]=0;
a[1]=1;
a[2]=2;
//Now, I would like to add a new element to my array by increasing its size by one
size += size; // new size is 4
我如何使用我的數組新的大小,並添加了新的元素添加到數組的結束?
但是,請記住,'memcpy'只能在[POD類型]使用(http://stackoverflow.com/questions/146452/what-are-pod-types-in-c)。 – 2011-05-08 01:33:30