如何删除数组? [英] How to delete an array?
问题描述
我是新手,所以PLZ给我一些渣; -)
无论如何,我需要删除一个数组,或者我真正需要的是增加
数组大小,我想我可以通过将数组复制到相同大小的
temorary数组来完成,然后删除原始数据,启动
$再次b $ b旧数组,但现在有更多的空格/单元格或者你称之为,然后
将teporary数组复制到刚刚创建的上,最后删除
临时数组。
a有点复杂,但我告诉它唯一的办法......
< blockquote> fe**********@hotmail.com sade:
我很新,所以plz给我一些渣;-)
无论如何,我需要删除一个数组,或者我真正需要的是增加
数组大小,我想我可以通过将数组复制到相同大小的同名数组来完成, n删除原文,再次启动旧数组,但现在有更多空格/单元格或者你调用它,然后将teporary数组复制到刚刚创建的上,最后删除
临时数组。
有点复杂,但我告诉它唯一的方法来做...
你走了:
int main(int argc,char * argv [])
{
//要扩展的数组
int * iptr = new int [5];
//分配新数组
int * temp = new int [8];
//将iptr复制到nptr
for(unsigned i = 0;我< 5; ++ i){
temp [i] = iptr [i];
}
//删除旧数组
delete [] iptr;
//将iptr重新指向新数组
iptr = temp;
temp = 0;
//删除数组
delete [] iptr;
返回0;
}
或者只是使用std :: vector而你不必处理上面的事情。
-
TB @ SWEDEN
< fe ********** @ hotmail.com>在消息中写道
news:11 ********************* @ f14g2000cwb.googlegro ups.com ...我很新,所以PLZ给我一些渣;-)
无论如何,我需要删除一个数组,或者我真正需要的是增加数组大小,我想我可以通过将数组复制到相同大小的同名数组,然后删除原始数据,再次启动
旧数组,但现在有更多的空格/单元格或什么你调用它,然后将teporary数组复制到刚刚创建的on和最后删除的温度数组。
有点复杂,但我告诉它唯一的方法来做...
看看标准C ++库 -
vector :: resize()
C ++提供序列容器的原因很多。
-ralph
是我写的,我是新的,我必须承认我没有完全理解所有的abo ve exprissions,howefer谢谢
答案生病看看它并返回以防我无法获得它
工作。
Hi, im pretty new to this so plz cut me some slag ;-)
anyhow, i need to delete an array, or what i really need is to increase
the array size, i was think i could be done by copying the array into a
temorary array of the same size, then delete the original, initiate the
old array again, but now with more spaces/cell or what u call it, then
copy the teporary array into the on just created and last delete the
temp array.
a bit complicated, but im told its the only way to do it...
fe**********@hotmail.com sade:Hi, im pretty new to this so plz cut me some slag ;-)
anyhow, i need to delete an array, or what i really need is to increase
the array size, i was think i could be done by copying the array into a
temorary array of the same size, then delete the original, initiate the
old array again, but now with more spaces/cell or what u call it, then
copy the teporary array into the on just created and last delete the
temp array.
a bit complicated, but im told its the only way to do it...
Here you go:
int main(int argc, char* argv[])
{
// The array which to extend
int * iptr = new int[5];
// Allocate new array
int * temp = new int[8];
// Copy iptr to nptr
for(unsigned i = 0; i < 5; ++i) {
temp[i] = iptr[i];
}
// Delete old array
delete[] iptr;
// Repoint iptr to new array
iptr = temp;
temp = 0;
// Delete array
delete[] iptr;
return 0;
}
Or just use std::vector instead and you won''t have to deal with the above.
--
TB @ SWEDEN
<fe**********@hotmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...Hi, im pretty new to this so plz cut me some slag ;-)
anyhow, i need to delete an array, or what i really need is to increase
the array size, i was think i could be done by copying the array into a
temorary array of the same size, then delete the original, initiate the
old array again, but now with more spaces/cell or what u call it, then
copy the teporary array into the on just created and last delete the
temp array.
a bit complicated, but im told its the only way to do it...
Take a look at the Standard C++ library -
vector::resize()
There are reasons C++ provides sequence containers.
-ralph
is i wrote, im pwer new to this and i must admit that i dont have a
complete understanding of all the above exprissions, howefer thanks for
the answer ill take a look at it and return in case i cant get it to
work.
这篇关于如何删除数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!