简体   繁体   English

向量值未按插入顺序

[英]Vector values not in inserting order

I'm inserting values into a vector: 我将值插入向量:
vector<map<vector<string> , vector<string> > > listedParameterMap;

like this: 像这样:
listedParameterMap.insert(listedParameterMap.end(), 1, parameterMap);

If I check later the vector, the order is inverted. 如果以后再检查向量,则顺序将反转。 Did I miss something? 我错过了什么?

EDIT: 编辑:
I think it may be somewhere else... I just got an idea. 我认为可能在其他地方...我刚有了一个主意。 But I'll try tomorrow. 但是我明天再试试。 I almost had today aleady at least one brain-stackoverflow with my code ;) 今天,我的代码几乎至少有一个大脑堆栈溢出;)

Anyway thank you all for helping. 无论如何,谢谢大家的帮助。 I'll tell if somthing changes! 我会告诉您一切是否变了!

EDIT2: 编辑2:
Seems like the error is somewhere else. 好像错误在其他地方。 I just could see where it happens, but until now not why. 我只是可以看到它发生的地方,但是直到现在还不知道为什么。 On a point where the map should get filled just once, it gets filled twice. 在地图只应填充一次的点上,地图将填充两次。 For some reason each time only on a specific value. 出于某种原因,每次只能使用一个特定的值。 That's why it was looking like the values are inverted. 这就是为什么看起来值倒置的原因。
If I need some help I'll open a new question. 如果需要帮助,我将打开一个新问题。 Thanks to everyone! 谢谢大家!


UPDATE: 更新:

The vector is ok now. 现在可以了。 Found the problem. 找到了问题。 Blindness of own code ;) 自己的代码失明;)

It doen't influence my programm my the map is inverted. 地图反转后,它不会影响我的程序。
I just created a new map inserting and then printing the values, this works then as expected. 我刚刚创建了一个新地图,然后插入并打印值,然后按预期工作。

Why don't you simply write: 你为什么不简单地写:

listedParameterMap.push_back(parameterMap);

It's simpler interface than what you're doing in your post. 它的界面比您在帖子中所做的要简单。

I can't make much sense of your sample code, but if you want to insert items into a vector in order, you usually want to use push_back . 我对示例代码没有多大意义,但是如果push_back顺序将项目插入向量中,通常需要使用push_back For a trivial example: 举个简单的例子:

std::vector<int> numbers;
for (int i=0; i<10; i++)
    numbers.push_back(i);

The numbers should now be in order, like: (1 2 3 4 5 6 7 8 9 10). 现在应该按顺序排列数字,例如:(1 2 3 4 5 6 7 8 9 10)。

I really don't think you want to do a map that uses a vector as a key, do you? 我真的不认为您想要绘制以向量为键的地图,是吗? This smells like you have more significant design problems. 这听起来像您有更多重大的设计问题。

As for adding stuff to vectors in a known (and presered order), use push_back(). 至于以已知的(和预设的顺序)向矢量添加内容的方法,请使用push_back()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM