标签:
pair有些时候比自己的定义的struct更方便。
1 #include <iostream> 2 #include <string> 3 #include <vector> 4 #include <algorithm> 5 using namespace std; 6 7 int main() 8 { 9 typedef pair<int, int> pii; 10 typedef pair<string, pii> psii; 11 vector<psii> grades; 12 grades.push_back(make_pair("a", make_pair(1, 2))); 13 grades.push_back(make_pair("a", make_pair(2, 1))); 14 grades.push_back(make_pair("a", make_pair(1, 3))); 15 grades.push_back(make_pair("b", make_pair(2, 1))); 16 grades.push_back(make_pair("b", make_pair(1, 1))); 17 grades.push_back(make_pair("c", make_pair(1, 1))); 18 19 sort(grades.begin(), grades.end()); 20 vector<psii>::iterator iter, iend = grades.end(); 21 for(iter = grades.begin(); iter != iend; ++iter) { 22 cout << iter->first << ‘ ‘ << iter->second.first << ‘ ‘ << iter->second.second << endl; 23 } 24 25 return 0; 26 }
标签:
原文地址:http://www.cnblogs.com/excavator/p/4841695.html