本文介绍了C ++字符数组的矢量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写有字符数组的矢量程序和我有一些问题。

I am trying to write a program that has a vector of char arrays and am have some problems.

char test [] = { 'a', 'b', 'c', 'd', 'e' };

vector<char[]> v;

v.push_back(test);

很抱歉,这已经是一个字符数组,因为我需要能够生成字符的名单,因为我想获得一个输出类似。

Sorry this has to be a char array because I need to be able to generate lists of chars as I am trying to get an output something like.

一个一个
A b
一个C
广告
A E
b A
B C

a aa ba ca da eb ab c

任何人都可以点我在正确的方向?

Can anyone point me in the right direction?

感谢

推荐答案

您不能存储在矢量阵列(或任何其他标​​准库容器)。的事情,标准库容器存储必须可拷贝和分配,和数组是没有这些。

You cannot store arrays in vectors (or in any other standard library container). The things that standard library containers store must be copyable and assignable, and arrays are neither of these.

如果你真的需要把一个数组中的向量(你可能不 - 用向量的向量或字符串矢量更有可能你所需要的),那么你可以用在结构数组:

If you really need to put an array in a vector (and you probably don't - using a vector of vectors or a vector of strings is more likely what you need), then you can wrap the array in a struct:

struct S {
  char a[10];
};

,然后创建结构向量:

and then create a vector of structs:

vector <S> v;
S s;
s.a[0] = 'x';
v.push_back( s );

这篇关于C ++字符数组的矢量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:46
查看更多