Here's the code, it can compile, but it can't run, why?:
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
typedef multimap<vector< int >, char> mmap;
mmap foo;
vector<int> v;
v.push_back(15);
v.push_back(14);
foo.insert(pair<vector< int >, char> (v, 'b'));
v.clear();
v.push_back(15);
v.push_back(80);
foo.insert(pair<vector< int >, char> (v, 'c'));
v.clear();
v.push_back(9);
v.push_back(17);
foo.insert(pair<vector< int >, char> (v, 'a'));
v.clear();
mmap::iterator iter;
for (int i = 0; i < iter->first.size(); ++i) {
wcout << iter->first[i] << " ";
for (iter = foo.begin(); iter != foo.end(); ++iter) {
wcout << iter->second << " ";
}
wcout << endl;
}
}
output:
15 80 c
15 14 b
9 17 a
I want to plus the integer,then sort it : (order the numbers from greatest to least
80+15>15+14>9+17
how to do that?
iter
to a valid iterator. - NathanOliverusing namespace std
- it is a bad habit to get into, and can silently change the meaning of your program when you're not expecting it. Get used to using the namespace prefix (std
is intentionally very short), or importing just the names you need into the smallest reasonable scope. - Toby Speight