#include <bits/stdc++.h>
using namespace std;
typedef pair <int , vector<int> > pairs;
void solve () {
set <pairs> s ;
for ( int i =0; i<5; i++){
vector<int> v ;
for ( int j = i; j<=i + i; j++){
v.push_back(j) ;
}
s.insert ({i,v}) ;
}
// printing values of set
for ( auto &x : s) {
cout<<x.first<<": ";
for ( auto i : x.second)
cout<<i<<" " ;
cout<<endl;
}
// searching for this <int,vector> pair in set
// to modify it
int val = 2 ;
vector<int> vf = {2,3,4} ;
auto it = s.find ( {val, vf} ) ;
if ( it != s.end() ) {
// printing some random stuff about this set element
cout<<(*it).first<<endl ;
cout<<(*it).second.size()<<endl ;
// inserting another value at the end of this vector
(*it).second.push_back(10001);
}
}
int main () {
solve() ;
return 0;
}
So in this code i m unable to modify the vector present in a set of pair of < int, vector<int> >
I found out that these lines of code works fine :
cout<<(*it).first<<endl ;
cout<<(*it).second.size()<<endl ;
but I m facing error to execute this line :
(*it).second.push_back(10001);
Why isn't push_back() operation not working here ? Any easy way to fix it ?