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
0
votes
1 answer

modifying vector at same iterator

Suppose i have the following vector: std::vector > myV; std::vector >::iterator it; And then i initialize them for 10 row: for (i = 0 ; i < 10; i++){ if (i % 2 == 0 ) j =…
PersianGulf
  • 2,845
  • 6
  • 47
  • 67
0
votes
2 answers

How do I declare a constant pair inside my header file

#include class C { private: const std::pair corner1(1,1); }; GCC reports error: expected identifier before numeric constant. I need to construct the object on the moment of it's declaration since it's const, but I can't…
Patrick.SE
  • 4,444
  • 5
  • 34
  • 44
-1
votes
0 answers

How to fix binary operator error C2678 for std::pair of both custom typedef struct Vec2 as a key value in std::map?

I have this code: std::pair vert_pair; vert_pair.first = vp2; // vp2 is Vec2 type vert_pair.second = vp1; // vp1 is Vec2 type std::map, void*> test; test[vert_pair]; // Error C2678 when compiling For example I…
skrovno_CZ
  • 35
  • 5
-1
votes
3 answers

Pair files using Python

I have a folder with several .tif files that I would like to pair to perform some functions inside a for loop. For example: smp001_GFP.tif smp001_mCherry.tif (this should be a pair) smp002_GFP.tif smp002_mCherry.tif (this another pair) I would like…
-1
votes
2 answers

How can I check, straight away, if a set of pairs have a commom number?

Suppose we have 4 pairs, e.g.: pair P1(1, 2); pair P2(3, 1); pair P3(2, 1); pair P4(1, 5); How can I compare those 4 pairs straight away and conclude that they all have the number 1 in common? I can only…
-1
votes
1 answer

ERROR: begin was not declared in this scope for(auto x:a)

pair getMinMax(long long a[], int n) { pair p; p.first=a[0]; // min p.second=a[0]; //max for(auto x:a) // for(int i=0; i
-1
votes
2 answers

Having a set of regex and a set of functions, how to link each regex to a specific function and then call that function once you have a match?

// vector of pairs vector> patterns; // store a regex pattern patterns[0].first = pattern; // store a function name patterns[0].second = func1; patterns[1].first = pattern2; patterns[1].second = func2; // take…
Ammarios
  • 19
  • 6
-1
votes
4 answers

Finding the lower bound of vector of pairs based on first value of pair

I have a vector of pair "v" which is sorted according to the first value of the pair. Now I want to find out the lower bound of vector "v" according to the first value of the pair -- while finding the lower bound I want to ignore the second. int pl;…
-1
votes
1 answer

Why is pair not working with unordered_map?

The following code doesn't compile. The line with pair is giving the error. Is there some other way to access the data or is this way correct?? unordered_map hm; unordered_map::iterator it; it=find(hm.begin(),hm.end(),x+c); if…
-1
votes
1 answer

inserting a double and a pair in map and printing the map

I want to build a container for fractions. The key will represent the value of the fraction in double; The numerator and the denominator are stored in a pair. std::map> m (); I had problems with inserting and printing…
Simona
  • 53
  • 1
  • 12
-1
votes
3 answers

How can I fix the missing template arguments before '(' token problem here?

I am getting the problem on line 15 and 20 where i am trying to pushback elements in to the pair vector #include #include #include using namespace std; int main() { int x, y, a, b, c, d, j, m, v; …
user13869329
-1
votes
1 answer

Unable to find the corner case I'm missing in a question I recently encountered

In yesterday's CodeChef contest I came across this problem in which I was able to write the code which was able to solve all the "normal" testcases, however, it failed when it came to a probable corner case that I seem to have missed. The question…
AyushGupta
  • 11
  • 2
-1
votes
1 answer

How to use numeric library function with a vector of pairs?

I am trying to use the function adjacent_difference from the numeric library on the second element of each entry of a vector of pairs (vector>). How can I do it? Update: here's my code so far (obviously wrong xD): vector…
-1
votes
1 answer

making second argument of std::pair a custom class

I am implementing a Node class in C++ as an assignment. The class : #pragma once #include class Node { size_t id; std::pair dist; public: //Node(); //Node(const size_t); Node(const size_t, const…
kesarling He-Him
  • 1,944
  • 3
  • 14
  • 39
-1
votes
1 answer

My C++ program is not working ...just got stuck in this dont know what to do

I wanted to take the values from user and wanted to sort it... so i took values in two arrays one in string array and the other in int array... if i sort the string array it get sorted very well.. i m not able to sort the int array accordingly....…