有没有办法让2个矢量混合在一起? [英] Is there a way to have 2 vectors mix together?

查看:80
本文介绍了有没有办法让2个矢量混合在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加2个向量进行打印,以便在同一行上。我想要做的是一个库存系统,它将使用2个向量来保持项目的磅数并在一行上列出2个向量。


(我使用的是Microsoft Visual C ++ 2010年快递)


喜欢这个:


0.空0

1.空0

2.空0

$ b $等...


现在看起来像这样:

0.空

0. 0


代码:

I want to add 2 vectors to print out so that there on the same line. What I am trying to make is an inventory system that will use 2 vectors to keep the pounds of the item and list the 2 vectors on one line.

(I am using Microsoft Visual C++ 2010 Express)

Like this:

0. empty 0
1. empty 0
2. empty 0

ect...

Right now it looks like this:

0. empty
0. 0

The code:

展开 | 选择 | Wrap | 行号

推荐答案

我是屁股每个矢量的大小是一样的吗?将cout线从第二个循环移动到第一个循环并摆脱第二个循环。
I''m assuming each vector is the same size? Move the cout line from the second loop into the first loop and get rid of the second loop.


我建​​议你只使用一个向量。


每个库存物品都有一个名称和磅数,因此您的设计应该模仿现实。在这种情况下,我将有一个名为InventoryItem的结构,结构成员将是名称的字符串和磅数的int。


那么你只有一个向量< InventoryItem>使用两个向量,确保第三个元素中的字符串与另一个向量中的第三个元素中的int保持同步是非常困难的。特别是因为矢量可以在不告诉你的情况下移动物品。
I suggest you use only one vector.

Each inventory item has a name and a number of pounds so your design should imitate reality. In this case I would have a struct named InventoryItem and the struct members would be a string for the name and a int for the number of pounds.

Then you only have a vector<InventoryItem>.

With two vectors, it''s too difficult to make sure the string in the 3rd element stays synched with the int in the 3rd element in the other vector. Especially since vectors can move items around without telling you about it.


我怎么能有一个模仿字符串和int的矢量?我没有正确地遵循,但是你想让我在矢量中同时包含磅和物品吗?由于矢量可以移动我的项目而没有注意到它会有什么帮助?
How could I have one vector that would imitate a string and int? I my not be following correctly but do you want me to have both pounds and the item inside the vector? Since the vector can move my items around with out notice how would that help?


这篇关于有没有办法让2个矢量混合在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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