矢量结构与向量 [英] vector of structs with vectors
问题描述
我有一个看起来像这样的门结构
/ *定义sGATE结构* /
struct sGATE
{
字符串名称;
vector< int>输入;
int输出;
};
我有一个这样的门矢量
/ *保持GATE向量* /
向量< sGATE> GATE;
现在,如何写入名称和< vector>输入GATE? :-)
GATE.push_back(name = currentstring); //不工作
GATE.push_back(currentstring); //绝对不会工作
GATE.push_back(...错误......我该怎么办?:-)
我认识你可以做一些像
GATE.name.push_back(stuffhere)如果门只是一件事。但现在它让我的生活变得更加复杂了。
有人能给我指点方向吗?
来想一想..也许我应该制作另一个结构并把它放在
push_back()..嗯..让我尝试一下,当我发布这个。希望
有更好的方法。
亲爱的mashurshi,
星期五,2005-09-09 12:18 -0700, ma ****** @ gmail .com 写道:
现在,如何写入名称和< vector>输入GATE? :-)
GATE.push_back(name = currentstring); //不工作
GATE.push_back(currentstring); //肯定不会工作
GATE.push_back(...错误......我该怎么办?: - )
vector< int> ; V(2,2); //或你向量所需的任何东西
sGATE sg = {" hoi",v,3};
GATE.push_back(sg);
祝福,
克里斯
嗯,我能看到的是,你不明白,矢量是什么。
试试这个:
sGate var;
// 1.要填写的项目在向量中
var.name.append(" abc");
var.input.push_back(1);
.. ..
GATE.push_back(var);
// 2.填写向量的项目
var.name.append(" ; xyz");
var.input.push_back(2);
....
GATE.push_back(var); < br $> b $ b ....
希望,这会有所帮助。
// oliver
< ma ****** @ gmail.com> schrieb im Newsbeitrag
news:11 ********************* @ g43g2000cwa.googlegro ups.com ...我有一个看起来像这样的门结构
/ *定义sGATE结构* /
struct sGATE
{
字符串名称;
vector< int>输入;
int输出;
};
我有一个像这样的门矢量
/ *保持GATE矢量* /
vector< sGATE> GATE;
现在,我如何写入名称和< vector>输入GATE? :-)
GATE.push_back(name = currentstring); //不工作
GATE.push_back(currentstring); //绝对不会工作
GATE.push_back(...错误......我该怎么办?:-)
我知道你可以做点赞/
GATE.name.push_back(stuffhere)如果门只是一件事。但是现在它让我的生活变得更加复杂。
有人能告诉我这里的方向吗?
来想一想..也许我应该做另一个结构并把它放在
push_back()..嗯..让我试试,当我发布这个。希望
有更好的方法。
yeap。我做了另一个结构的变量并放在里面
push_back()
感谢快速回复人们。
I''ve got a gate structure that looks like this
/* Defining sGATE structure */
struct sGATE
{
string name;
vector<int> input;
int output;
};
And I have a vector of gates like this
/* Keeping GATE vector */
vector <sGATE> GATE;
Now, how do I write into name and <vector> input of a GATE? :-)
GATE.push_back(name=currentstring); //doesn''t work
GATE.push_back(currentstring); //definitely doesn''t work
GATE.push_back( ... err... what should i do? :-)
I know you can do something like
GATE.name.push_back(stuffhere) if gate was just a single thing. but
now it made my life a bit more complicated.
Could someone show me a direction here ?
come to think of it.. maybe i should make another struct and put it in
push_back() .. hmm.. let me try that while i post this. hopefully
there''s a better way.
Dear mashurshi,
On Fri, 2005-09-09 at 12:18 -0700, ma******@gmail.com wrote:
Now, how do I write into name and <vector> input of a GATE? :-)
GATE.push_back(name=currentstring); //doesn''t work
GATE.push_back(currentstring); //definitely doesn''t work
GATE.push_back( ... err... what should i do? :-)
vector<int> v(2,2); // or whatever you need for your vector
sGATE sg={"hoi",v,3};
GATE.push_back(sg);
Best wishes,
Chris
Well, what I can see, is, that you do not understand, what a vector is.
Try this:
sGate var;
// 1. item to fill in the vector
var.name.append("abc");
var.input.push_back(1);
....
GATE.push_back(var);
// 2. item to fill in the vector
var.name.append("xyz");
var.input.push_back(2);
....
GATE.push_back(var);
....
Hope, this helps.
// oliver
<ma******@gmail.com> schrieb im Newsbeitrag
news:11*********************@g43g2000cwa.googlegro ups.com...I''ve got a gate structure that looks like this
/* Defining sGATE structure */
struct sGATE
{
string name;
vector<int> input;
int output;
};
And I have a vector of gates like this
/* Keeping GATE vector */
vector <sGATE> GATE;
Now, how do I write into name and <vector> input of a GATE? :-)
GATE.push_back(name=currentstring); //doesn''t work
GATE.push_back(currentstring); //definitely doesn''t work
GATE.push_back( ... err... what should i do? :-)
I know you can do something like
GATE.name.push_back(stuffhere) if gate was just a single thing. but
now it made my life a bit more complicated.
Could someone show me a direction here ?
come to think of it.. maybe i should make another struct and put it in
push_back() .. hmm.. let me try that while i post this. hopefully
there''s a better way.
yeap. i made another variable of that struct and placed inside
push_back()
thanks for the quick replies folks.
这篇关于矢量结构与向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!