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
-2
votes
3 answers

Which method is to access Pairs?

just to clear this doubt of fine i just want to ask that which method is faster or more efficient to access pairs while iterating over a contiguous block of pairs. I used two method to iterate over a block. 1st pair arr[3] = {{1, 'a'},…
Vasu saini
  • 21
  • 6
-2
votes
2 answers

Why do return boolean value in this line std::unordered_map<>.insert().second in C++

std::unordered_map url; url.insert(std::pair("google","www.google.co.kr")); bool ok = url.insert(std::pair("google","www.google.com")).second; std::cout << (ok ?…
Kwon34
  • 11
-2
votes
1 answer

Is there a size() member function for std::pair?

I was following a hash table implementation tutorial and came across this: class HashTable { private: static const int hashGroups = 10; std::list> table[hashGroups]; bool HashTable::isEmpty() const { int…
-2
votes
1 answer

In c++ code, set.erase(it) is halting execution, where it=set.begin() for a set of pairs, why is this happening?

Sorry for any inconvenience I am a beginner at C++ and was stuck with an empty set... Thank you for the helpful comments that helped me figure out what the problem was I wrote a C++ code for a question in which I need to use Dijkstra's shortest path…
-2
votes
3 answers

warning: character constant too long for its type car.second = 'Sarim';

I want to make a pair of int and string. As: pair car ; car.first = 10; car.second = 'Sarim'; cout<
SARIM
  • 992
  • 3
  • 14
  • 22
-2
votes
2 answers

How to push a value inside a vector which in a c++ pair?

I have come across a scenario where I am not able to find a way to push a value in the vector which is in the pair. I have made a priority_queue of pair> and I want to push values in the vector, for…
-2
votes
2 answers

Why std::pair doesn't compare with std::string?

Why I can't compile the code bellow? string m = "MEOW"; pair p = { "M", 0 }; if (m[0] == p.first) p.second += 10; I get the error: main.cpp:18:14: error: invalid operands to binary expression ('int' and…
Jeffy
  • 71
  • 1
  • 5
-2
votes
2 answers

Accessing values of a map that containing a vector pair

I declared a map that contains a vector pair like typedef vector> vectorPair; map mapName; I've been trying to iterate through the map with an iterator and I'm confused as to how I access the vector pair from…
user10416464
-2
votes
2 answers

How to insert an element in a vector of pair of set? vector>>

vector>>m1; I am trying to insert an element where each int will hold several strings using set. How to insert an element in this? I tried like this. vector>>m1; int p,n,i; cin>>p>>n; …
Joy Sinha
  • 11
  • 2
-2
votes
2 answers

Return only the first element of an std::pair when calling a function that returns std::pair

I'm using a function that returns an std::pair: std::pair myFunction() { //Do something... if (success) { return {true, someValue}; } else { return {false, someOtherValue}; } } On success, the pair's…
Julini
  • 45
  • 1
  • 7
-2
votes
1 answer

Find unique quadruplets in C++

So, I need to find unique quadruples in C++. Any idea would help Input 1 : [1, 0, 2, 3], [2, 0, 1, 3], [4, 5, 6, 7], [8, 9, 10, 11] Output 1 : [2, 0, 1, 3], [4, 5, 6, ,7], [8, 9, 10, 11] As [1,0,2,3] and [2,0,1,3] both contain same elements so…
pranavhd
  • 25
  • 7
-2
votes
2 answers

Pair cpp or use a map to fill and print

I dont know how to include a map or a pair in this code below to print ou a list in format A:1 B:2 C:3 #include using namespace std; #include #include int main() { // your code goes here char letter = 'A'; …
Tahtoh
  • 75
  • 1
  • 10
-2
votes
2 answers

Printing the elements of vector

In the following code, I have a 2D vector,in each index of vector each pair contains int and string. I am trying to access the each element after taking the values in the vector. Suggestions will be very much appreciated. #include
Shovo
  • 133
  • 2
  • 9
-2
votes
1 answer

Using a pair as a parameter from another function

I asked this question before but the suggestions don't work so I have tried to make my question more clear. I have a function that returns a std::pair but the parameters for the function as follow function(int g, double a);. This…
May
  • 15
  • 1
  • 1
  • 3
-2
votes
1 answer

How to get a C++ pair to compile

I am trying to compile a very complicated code and I get the error g++ -o MCBody MCBody.cpp MCBody.cpp:36:34: error: expected initializer before ‘<’ token double numericalIntegration::pair integrate(double (*pFun)(const double &…
ianacp
  • 9
  • 2