变长数组的数组 [英] Array of Variable Length Arrays
本文介绍了变长数组的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通常情况下,我们可以这样写:
为const char * names1 [] = {栈,LongerThanStack};
为const char * names2 [] = {溢出,LongerThanOverflow,O};
如何使一个新的数组名称
包含上述两个数组?
二维数组应该这样做。
我尝试以下code,但 G ++
并没有接受,因为内部数组的长度可变的。
为const char *名称[2] [] = {{栈,LongerThanStack},
{溢出,LongerThanOverflow,O}};
解决方案
除非你有一个pressing不需要,像这样做:
的std ::矢量<的std ::矢量<标准::字符串>>名字= {{栈,LongerThanStack,S},{溢出,LongerThanOverflow,O}};
Normally, we can write this :
const char* names1[] = { "Stack", "LongerThanStack" };
const char* names2[] = { "Overflow", "LongerThanOverflow", "O" };
How to make a new array names
that contains the above two arrays ?
Two dimensional arrays should do this.
I tried the following code, but G++
didn't accept it because of the variable length of the inner array.
const char* names[2][] = {{ "Stack", "LongerThanStack" },
{ "Overflow", "LongerThanOverflow", "O" }};
解决方案
Unless you have a pressing need not to, do it like this:
std::vector<std::vector<std::string>> names = {{ "Stack", "LongerThanStack", "S" }, { "Overflow", "LongerThanOverflow", "O" }};
这篇关于变长数组的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文