std::map is a class in the C++ Standard Library. It is a sorted associative container that contains key-value pairs with unique keys. Search, removal, and insertion operations have logarithmic complexity. Maps are usually implemented as red-black trees.
Questions tagged [stdmap]
1446 questions
-3
votes
2 answers
std map find is always true
I have a problem using the std::map, specifically when using find.
I have the following code.
class MyClass
{
update(const QVariant&);
QVariant m_itemInfo;
std::map m_testMap;
}
void update(const QVariant& itemInfo)
{
…

Frank
- 2,446
- 7
- 33
- 67
-3
votes
2 answers
How to iterate std::map values in my own order / the order they were inserted?
Suppose I have a std::map and I've inserted the following values:
3, 5, 2, 1, 4, 6
By default std::map will iterate them in sorted order:
1, 2, 3, 4, 5, 6
But I want to iterate them in Insertion order:
3, 5, 2, 1, 4, 6
Can anyone tell me how can…

Sondhi
- 51
- 1
- 4
- 9
-3
votes
2 answers
std::map check if a map has been assigned a non-default value?
Lets say I have a complex map defined as
std::map, float> > complex_map;
Let us assume I initialized this map as
for (int k=0;k<5;k++)
{
std::pair< vector, float> complex_map_child;
…

suzee
- 563
- 4
- 25
-3
votes
2 answers
Inserting in map >
Why is the following code not inserting elements in the map > ?
(The size of all the sets after executing the following code is 0.)
I am creating an adjacency list in this map.
map > m;
cin>>n;
while(n--)
{
cin>>t;
…

piXel_pRo
- 159
- 2
- 14
-3
votes
2 answers
pointer to std::map fails to insert
I am very confused. Why does this work:
double doubleValue = 20;
NcVar variable = {some process obtaining an instance}
map th;
th.insert(std::make_pair(variable, doubleValue));
and this fails:
double doubleValue = 20;
NcVar variable =…

Jürgen Simon
- 876
- 1
- 12
- 35
-3
votes
2 answers
Odd behavior of try/catch
My question is this: why does the following code:
class A
{
public:
A()
{
test[0] = "three";
test[5] = "five";
test2[3] = 5.55;
}
void foo(int j)
{
for(int i = j+1; i <= 7; ++i)
{
…

user1233963
- 1,450
- 15
- 41
-3
votes
1 answer
[] operator in std::map is giving me segmentation fault
I have a
std::map myMap
then I am inserting like follow:
if(!myKey.empty())
{
myMap[myKey] = this;
}
This sometime is throwing a segmentation fault.
Why??

Kam
- 5,878
- 10
- 53
- 97
-4
votes
0 answers
Why std::map::erase(iterator pos) cause segfault while std::map::erase(iterator first, iterator last) do not?
My goal is to understand this statement
Correctness: In particular, pay attention to the validity of iterators. It is illegal to dereference end iterators. Consider using a checking STL implementation such as the one shipped with Visual C++ or…

Jason Rich Darmawan
- 1,607
- 3
- 14
- 31
-4
votes
1 answer
Find element in std::vector which is also present in in a std::map
I would like to get an iterator of each element in an std::vector that is also present in a std::map (as .first or as a key).
How would I best go about this in an efficient manner?

stdcerr
- 13,725
- 25
- 71
- 128
-4
votes
3 answers
std::pair of strings as custom key of unordered_map defined in std fails with template errors
I have a map defined and used like this
// def.h
struct X{};
struct Y{};
struct myStruct
{
X x;
Y y;
};
typedef std::unordered_map, myStruct> myMap;
namespace std
{
template<> struct pair

Hello Everyone
- 329
- 4
- 11
-4
votes
2 answers
C++ map with custom comparator not inserting all elements
I have created the following comparator to test the map:
struct comparator{
bool operatior() (int a,int b){
return 1;
}
}
then the following algorthim:
int main(){
// imports string to currentString
...
…

Henrickunit
- 1
- 3
-4
votes
1 answer
std::map key value pairs not iterating in sequence
I am inserting key value pairs in a std::map as
key = //something;
value = //something;
demoMap[key] = value;
Printing the key and value here gives me correct results. However, when I iterate this map as:
for( std::map

Kamalpreet Grewal
- 822
- 1
- 13
- 28
-4
votes
2 answers
Initialize map with pair of std::arrays c++11
I would like to compile this lines. Insert to map pair of std::arrays.
#include
#include
-5
votes
2 answers
arrange by Frequency
Task: design a function such that it returns a sorted vector pair with highest frequency element first and if two elements have same frequency, arrange them in sorted order(increasing) by element.
Does it have any conceptual error?
Is it possible to…

Agniveer
- 371
- 2
- 18
-5
votes
2 answers
c++ get a vector from a map of vectors
I have a map of vector
map< int, vector > hit = getAlignedHits();
I want to get the vector paired with a specific key, such as:
vector vec;
vec = hit[1];
The error I get is:
candidate function not
viable: no known conversion…

Eda Yıldırım
- 25
- 2
- 6