你什么时候会使用一个数组而不是一个向量/字符串? [英] When would you use an array rather than a vector/string?

查看:265
本文介绍了你什么时候会使用一个数组而不是一个向量/字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个初学者的C ++程序员,所以我一直使用数组而不是向量(这个似乎是做事情的一般方式,然后转移到载体稍后)。据悉

I'm a beginner C++ programmer and so I've learnt using arrays rather than vectors (this seems to be the general way to do things, then move on to vectors later on).

我注意到有很多对SO答案建议使用超过阵列载体和字符串在字符数组。看来,这是正确的方法在C + + code。

I've noticed that a lot of answers on SO suggest using vectors over arrays, and strings over char arrays. It seems that this is the "proper" way to code in C++.

这一切都这样说,当它仍然是值得使用的是经典阵列/炭*(如果有的话)?

That all being said, when is it still worth using a classic array/char* (if ever)?

推荐答案

在写code,如果你的目标特殊平台(嵌入式,游戏机等)应在其他项目中使用,特别是在STL可能​​不是present。

When writing code that should used in other projects, in particular if you target special platforms (embedded, game consoles, etc.) where STL might not be present.

旧的项目或有特殊要求的项目,可能不希望对STL库引入的依赖关系。这取决于阵列,烧焦*或因为它是语言的一部分任何将与任何兼容的接口。但是STL不保证为present在所有构建环境。

Old projects or projects with special requirements might not want to introduce dependencies on STL libraries. An interface depending on arrays, char* or whatever will be compatible with anything since it's part of the language. STL however is not guaranteed to be present in all build environments.

这篇关于你什么时候会使用一个数组而不是一个向量/字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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