如果数组在C ++中使用? [英] Should arrays be used in C++?

查看:152
本文介绍了如果数组在C ++中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于的std ::列表的std ::矢量存在,有没有理由使用传统的C数组在C ++中,还是应该尽量避免的,就像的malloc

Since std::list and std::vector exist, is there a reason to use traditional C arrays in C++, or should they be avoided, just like malloc?

推荐答案

在C ++ 11,其中的 的std ::阵列 是可用的,答案是是的,阵列应该避免。此前C ++ 11,您可能需要使用C数组中的自动存储阵列分配(即在栈上)。

In C++11 where std::array is available, the answer is "yes, arrays should be avoided". Prior to C++11, you may need to use C arrays to allocate arrays in the automatic storage (i.e. on the stack).

这篇关于如果数组在C ++中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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