The easiest way is to use map :
int main() { vector<int> a; for(int i = 0; i < 100; ++i) a.push_back(rand()%20); map<int,int> v; for(auto i: a) v[i]++; for(auto i: v) cout << setw(3) << i.first << setw(10) << i.second << "\n"; }
If you really want a vector - sort it out, and go through it, collecting the same values ​​into pairs vector ...
int main() { vector<int> a; vector<pair<int,int>> b; for(int i = 0; i < 100; ++i) a.push_back(rand()%20); sort(a.begin(),a.end()); pair<int,int> p{a[0],1}; for(int i = 1; i < a.size(); ++i) { if (p.first == a[i]) { p.second++; continue; } b.push_back(p); p = { a[i], 1 }; } b.push_back(p); for(auto i: b) cout << setw(3) << i.first << setw(10) << i.second << "\n"; }