Questions tagged [std-pair]

A std::pair is an ordered, heterogeneous sequence of exactly two objects (it is a special case of std::tuple).

std::pair is a part of the C++ Standard Library, defined in the header <utility>.

Reference: https://en.cppreference.com/w/cpp/utility/pair

776 questions
-1
votes
1 answer

How can I access pair

unordered_map> _sets; Let's say I have a key called _key, how can I access the data in the unordered_map? How can I get the data type T and int from the pair<>?
-1
votes
2 answers

initialize a static const std::pair>

I have a class myclass { // ... static const vector>> var; // ... }; in the class definition, to use mappings of single strings to several others. I am using vector<> instead of arrays, in order to be able to…
npit
  • 2,219
  • 2
  • 19
  • 25
-1
votes
2 answers

For every word output a list of pairs, the line number and the word count of that line

I'm trying to write a program for every word in stdin, output a list of pairs of the form L:N where L is a line number and N is the number of occurrences of the given word. So if stdin is: hello world hello hello the output should be hello 1:1…
-1
votes
3 answers

compare function for pairs not working

I have written my own compare function to sort a vector of pairs. My sort function should be like this. The point (i,j) will be ahead of point(x,y) if it is closer to (5,5), vice-versa. I am finding the distance and then comparing based on that. …
user3126404
-1
votes
1 answer

Changing std::pair type affects hashmap

Initially I had code that looked like this: std::map< std::pair, std::vector > aMap; It worked. Now I have code that looks like this: std::map< std::pair, std::vector > aMap; It no longer maps…
Tring Vu
  • 253
  • 1
  • 10
-1
votes
1 answer

std::make_pair (no matching function for make_pair)

std::pair, int> MyClass::get_drag_info() { return std::make_pair, int>( m_drag_targets, m_drag_data_format); } Why the above function does not work? and how do I…
codekiddy
  • 5,897
  • 9
  • 50
  • 80
-1
votes
2 answers

C++ map::find for pair as key

I have a map of pair as key and bool as value. When i try to find a certain pair that is already included using map::find method, it's not finding any item. What do i do wrong? I tried to implement a comparator class and set it as key_comp in map,…
Radu Vlad
  • 1,474
  • 2
  • 21
  • 37
-1
votes
3 answers

map undeclared : first use in the function error

#include #include int main() { int cases, i, j, act, answer, min_ind, min_val, temp1, temp2; scanf("%d",&cases); for(i=0; i mymap; …
Mcolorz
  • 145
  • 1
  • 5
  • 20
-1
votes
1 answer

A program using class template, pair, vector

I'm trying to program the following: A template class map having a pointer to a vector that contains elements std::pair, where T and Q are template types. It's supposed to work similarly to std::map and T is 'key' type, whereas Q stands for…
-1
votes
1 answer

Two Different Classes Double linked list and Pair class that won't work together

I am writing a program that is like boggle, but that has much less difficulty. My program program is meant to receive the number of Lines of Letters (all same amount of letters) and then receive on separate lines the Letters. Proceeded by the…
Kurt E
  • 367
  • 1
  • 2
  • 9
-1
votes
2 answers

Browse vector with std::vector >

I have the following vector: std::vector< std::pair > myvec; How can i browse and print elements of my vector with iterators?
PersianGulf
  • 2,845
  • 6
  • 47
  • 67
-1
votes
2 answers

C++ pair data type issue

I am writing a friend recommendation algorithm and in a part I have to store 350 random friendship using the data type std::pair in C++. I basically use an adjacency list (implemented as vector of vectors). I create a vector that stores data type…
Ali
  • 5,338
  • 12
  • 55
  • 78
-2
votes
1 answer

How to use std::pair with classes?

so I'm experimenting with cvc5 and just wanted to keep track of the Terms in a map so I have created this: std::map> terms; Basically, for I used the name as an index and I store the Term with other info in the…
Alberto
  • 446
  • 5
  • 14
-2
votes
1 answer

how do i print elements of vector of pair?

#include #include #include int main() { std::vector> v; v.push_back({10,20}); // This works std::cout << v[0].first << " " << v[0].second << "\n"; // But I'd like to just be…
-2
votes
2 answers

How to update values in C++ std::pair

I have this function that returns the location of a robot (which is just a [row][col] pair of indices from a matrix): std::pair World::getRobotLocation(char robot_name){ auto const & location = robots.find(robot_name); if (location…
Onur-Andros Ozbek
  • 2,998
  • 2
  • 29
  • 78