值追加到c数组 [英] Appending values to c array

查看:151
本文介绍了值追加到c数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个很简单的问题,但我不知道如何做到这一点。

This is a very simple question, but I don't know how to do this.

例如,我有一个名为阵列阵列包含值 [1,2,3,4,5,6] ,我想添加第七值, 7 ,到阵列使其包含 [1,2,3,4, 5,6,7]

For example, I have an array called Arraycontaining the values[1,2,3,4,5,6], and I want to add a seventh value, 7, to the array so it contains[1,2,3,4,5,6,7].

有一个函数来做到这一点?我是否需要任何多余的头文件?任何帮助将是AP preciated。

Is there a function to do that? Do I need to include any extra header files? Any help would be appreciated.

推荐答案

如果它被宣布为这样一个普通数组:

If it is a plain array declared as such:

int Array[] = {1,2,3,4,5,6};

那么你就不能多值添加到它。如果有提前提供了一些空间,然后您可以添加更多的值:

Then you wouldn't be able to add more values to it. If there's some space provided in advance then you may add more values:

int Array[7] = {1,2,3,4,5,6};
Array[6] = 7;

如果您使用C ++,我会建议使用的std ::矢量,但它不存在C。

If you used c++, I would recommend using std::vector, but it does not exist in C.

这篇关于值追加到c数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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