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

How to assign starting address to an interator of a map,long long int >

I created a map of a pair and long long int - map< pair< long long int, long long int >,long long int >; and an interator - map< pair< long long int, long long int >, long long int >::iterator it1; and when I did it1=same.begin() the compiler…
user3111412
  • 177
  • 1
  • 3
  • 11
0
votes
1 answer

How to access elements of a pair set in C++

I have a set. It is of the form set > stockSet I want find if the above set has an entry for a given string that is first element. Also to find the value of 2nd part of the pair, that is int given the first element of the pair…
0
votes
0 answers

Std::pair or create a struct

We have a discussion on using std::pair or some own struct for Snake game column and row. Do we need to create something like that: struct { int row; int col;} ... cell.row, cell.col; Or use: std::pair ... cell.first, cell.second;
vityo
  • 1
0
votes
1 answer

stl map having pair which contains array

I need help in implementing a design: I have MessageID's(integer Macros) declared in project. Each MID is associated one or more sources(enum 0 -19). By checking each source of MID, I want to call different functions. My followed following approach:…
0
votes
1 answer

How to insert value in c++ map std::map in c++?

I am trying to insert a value in map where key to map is string and value is list. When I try to insert then I am getting error. #include #include #include #include #include using namespace std; main() { …
Mehul Donga
  • 105
  • 3
  • 14
0
votes
3 answers

Iterate over vector using first value of std::pair only

I have a std::vector as described below: std::vector> matrix; This vector has the following values (for e.g.): values (as an example) These values can be access here as follows: matrix[0] = [0,Hello] // pseudo code (only…
cryengineplus
  • 61
  • 1
  • 3
0
votes
2 answers

How to erase a pair element in a list

list> li{{5,6},{7,8},{9,10}}; for(auto it=li.rbegin();it!=li.rend();++it) { cout << (*it).first << (*it).second << '\n'; li.erase(it); } error: no matching function for call to 'std::list
Milo Lu
  • 3,176
  • 3
  • 35
  • 46
0
votes
2 answers

Create tuples consisting of pairs of words

I have a string (or a list of words). I would like to create tuples of every possible word pair combination in order to pass them to a Counter for dictionary creation and frequency calculation. The frequency is calculated in the following manner: if…
Toly
  • 2,981
  • 8
  • 25
  • 35
0
votes
1 answer

Print adjacency list with weights

So, I made this adjacency list using vector, list and pair and now I want to print it on the screen. I've seen some codes printing vector< pair<..> >, but I don't know how to do it with a list. I've put a iterator at the end, but I don't know what…
0
votes
4 answers

c++ pair template struct declaration ambiguity!

In definition of pair class in c++ there are two typedefs. what are they for? there are no use of them in the code! template struct pair { typedef T1 first_type; typedef T2 second_type; T1 first; T2 second; pair() :…
Kamran
  • 451
  • 1
  • 5
  • 13
0
votes
1 answer

vector accessing non zero elements but output as zero

I' did this program what suppose save pairs of string ,int on one vector and print the strings of the maximum number on vector but when i try to find this strings don't appears nothing so I try print all values of int's on vector and although was…
warwcat
  • 309
  • 3
  • 5
  • 13
0
votes
1 answer

Confusion with std::pairs initialization

The code below, when compiled produces the following errors: error C2439: 'std::pair::first' : member could not be initialized error C2440: 'initializing' : cannot convert from 'int' to 'const AnalyticsToolKit::ParcelPassingLogic::ParticipantNode…
0
votes
5 answers

STL pair comparison - first elements

Can someone explain meaning of this paragraph The great advantage of pairs is that they have built-in operations to compare themselves. Pairs are compared first-to-second element. If the first elements are not equal, the result will be based on the…
Varun Garg
  • 2,464
  • 23
  • 37
0
votes
2 answers

Generic symmetric pair c++ for double and single types

I am trying to have a template structure which can handle symmetric pairs. The comparisons operators are implemented to make the struct work in std::map. So far I am using the following code : template struct SymmetricPair { …
coincoin
  • 4,595
  • 3
  • 23
  • 47
0
votes
2 answers

C++11 vector with two GLfloats as pair fail to uniform initialize

The error message of gcc 4.9.2 is: could not convert from '' to 'std::vector >' of this code: vector> LightOneColorsPairVec {{0.5f, 0.5f, 0.5f, 1.0f}, {0.0f, 0.0f,…
moonwalker
  • 1,157
  • 1
  • 18
  • 34