I have an input of:
1 a
2 b
..
I would like to insert them to a vector of pairs, with copy function, like this:
#include <vector>
#include <iterator>
#include <algorithm>
#include <iostream>
int main(void) {
std::vector<std::pair<int, char>> v;
std::copy(std::istream_iterator<std::pair<int, char>>(std::cin), std::istream_iterator<std::pair<int, char>>(), std::back_inserter(v));
for(auto pair: v)
std::cout << pair.first << std::endl;
return 0;
}
However, this will not compile: error: no match for 'operator>>'
, since it probably needs an operator overloading.
Does that mean that I will have to create my own class, which inhertis from std::vector
, and then overload the operator?
I would like to avoid using my own class, instead of the standard vector class.