矢量的char数组 [英] vector of char arrays

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

问题描述

我有这样一个固定大小的字符串数组


char m_titles [80000] [8];


并且可以''弄清楚如何将它改为动态大小的矢量,如

这个:


std :: vector< char [8]> m_titles;


声明编译但随后调用reserve或resize导致

模糊编译器错误。可以这样做,以便它分配一个大的
字符数组,而不是80000堆字符串?


-

Scott McPhillips [VC ++ MVP]

I have a fixed-size string array like this

char m_titles[80000][8];

and can''t figure out how to change it to a dynamically-sized vector like
this:

std::vector<char[8]> m_titles;

The declaration compiles but then calling reserve or resize leads to
obscure compiler errors. Can this be done so that it allocates one big
array of chars, not 80000 heap strings?

--
Scott McPhillips [VC++ MVP]

推荐答案

Scott McPhillips [MVP]写道:
Scott McPhillips [MVP] wrote:
我有一个固定的 - 像这样的字符串数组

char m_titles [80000] [8];

并且无法弄清楚如何将其更改为动态大小的矢量
像这样:

std :: vector< char [8]> m_titles;

声明编译但随后调用reserve或resize导致
模糊编译器错误。


是的,这无法兼顾复制可兼容性和可转让性。

可以这样做,以便它分配一个大的字符阵列,而不是80000堆字符串?
I have a fixed-size string array like this

char m_titles[80000][8];

and can''t figure out how to change it to a dynamically-sized vector
like this:

std::vector<char[8]> m_titles;

The declaration compiles but then calling reserve or resize leads to
obscure compiler errors.
Yeah, this fails both copyconstuctibility and assignability.
Can this be done so that it allocates one
big array of chars, not 80000 heap strings?




你可以使用一个带有成员数组的结构,但是你不能确定它不会是

实例之间的填充。


Jonathan



You can use a struct with a member array, but you can''t be sure there won''t be
padding between the instances.

Jonathan


Scott McPhillips [MVP]写道:
Scott McPhillips [MVP] wrote:
我有像这样的固定大小的字符串数组

char m_titles [80000] [8];

并且无法弄清楚如何将其更改为动态大小的向量喜欢
这个:

std :: vector< char [8]> m_titles;

声明编译但随后调用reserve或resize导致
模糊编译器错误。可以这样做,以便它分配一个大的字符数组,而不是80000堆字符串吗?
I have a fixed-size string array like this

char m_titles[80000][8];

and can''t figure out how to change it to a dynamically-sized vector like
this:

std::vector<char[8]> m_titles;

The declaration compiles but then calling reserve or resize leads to
obscure compiler errors. Can this be done so that it allocates one big
array of chars, not 80000 heap strings?



问题是char [8]类型是不可分配的所以它不会在向量内工作




你可以做矢量矢量,

或字符串向量,



struct c8 {

char c [8];

};

vector< c8>


The problem is that the type char[8] isn''t assignable so it''s not going
to work inside a vector.

You could either do a vector of vector,
or a vector of strings,
or
struct c8 {
char c[8];
};
vector<c8>




" Scott McPhillips [MVP]" < ORG-点的MVP-AT-scottmcp>在消息中写道

news:8o ******************** @ comcast.com ...

"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in message
news:8o********************@comcast.com...
I有这样一个固定大小的字符串数组

char m_titles [80000] [8];

并且无法弄清楚如何将其更改为动态大小矢量如
这个:

std :: vector< char [8]> m_titles;

声明编译但随后调用reserve或resize导致
模糊编译器错误。可以这样做,以便它分配一个大的字符数组,而不是80000堆字符串?
I have a fixed-size string array like this

char m_titles[80000][8];

and can''t figure out how to change it to a dynamically-sized vector like
this:

std::vector<char[8]> m_titles;

The declaration compiles but then calling reserve or resize leads to
obscure compiler errors. Can this be done so that it allocates one big
array of chars, not 80000 heap strings?




标准容器需要包含的对象

可以复制和分配。数组不合格。


使用向量向量。


-Mike



Standard containers require that the contained objects
be copyable and assignable. Arrays do not qualify.

Use a vector of vectors.

-Mike


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

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