从 C++ 数组中删除元素 [英] Delete element from C++ array

查看:81
本文介绍了从 C++ 数组中删除元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我如何从 C++ 数组中删除一个元素.

Please tell me how to delete an element from a C++ array.

我的老师将它的值设置为 0,对吗?

My teacher is setting its value to 0, is that correct?

推荐答案

你不能真正从 C++ 数组中删除"一个元素.

You can't really "delete" an element from a C++ array.

但是,如果数组由指针组成,则可以删除特定元素指向的对象.

However, if the array consists of pointers, you can delete the object that a specific element points to.

在您老师的例子中,重要的是要注意数组的对象是否是动态分配的(使用 C++ 中的 new 运算符).他可能只是将他的值设置为 0 作为该值不再有效的指示.

In your teacher's case, it will be important to make note of whether the objects of the array are dynamically allocated (using the new operator in C++) or not. He may simply be setting his values to 0 as an indicator that the value is no longer valid.

没有实际的源代码,我能帮到你的就这么多了.

Without actual source code, this is as much as I can help you with.

这篇关于从 C++ 数组中删除元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆