-1

I have to print the values of a pair. For showing the value of the first value of the pair there isn't any problem. But how I can print the second value of the pair? The representation can't be changed.

typedef vector<char> _vots;
typedef pair<string,_vots> PartitPolitic;

ostream& operator<<(ostream &o, PartitPolitic x){
   o << x.first << endl;
   o << x.second << endl;->>>>>>>>>>>>>>>>> ERROR
   return o;
}

int main(){
      vector<PartitPolitic> partit;
      string q;
      string s;
      getline(cin,descripcio);
      while (q!="*"){
          getline(cin,s)
          _vots v(s.begin(),s.end());
          PartitPolitic f(descripcio,v);
          partit.push_back(f);
          getline(cin,descripcio);
     }
     vector<PartitPolitic>::iterator it =partit.begin();
     while(it!=partit.end()){
        cout << *it << endl;
        it++;
     }
     return 0;
}
Emil Laine
  • 41,598
  • 9
  • 101
  • 157
Arnau
  • 19
  • 1
  • 1
  • 4

1 Answers1

2

how I can print the second value of the pair?

The second value is a vector<char>, so to print that you need to provide an operator<< overload for vector, defining how you want a vector to be printed:

template<typename elem_type>
ostream& operator<<(ostream &o, vector<elem_type> const& v) {
   for (const elem_type& e : v)
      o << e << ",";
   return o;
}

or you can simply output the vector manually in operator<<(ostream&, PartitPolitic):

ostream& operator<<(ostream &o, PartitPolitic x) {
   o << x.first << endl;
   for (char e : x.second)
      o << e << ",";
   return o;
}
Emil Laine
  • 41,598
  • 9
  • 101
  • 157