c++ map 官方样例
#include <iostream> #include < string > #include <iomanip> #include <map> template <typename Map> void print_map(Map& m) { std::cout << ' { ' ; for (auto& p : m) std::cout << p.first << " : " << p.second << ' ' ; std::cout << ' } ' << std::endl; } struct Point { double x, y; }; struct PointCmp { bool operator ()( const Point& lhs, const Point& rhs) const { return lhs.x < rhs.x; } }; int main() { using namespace std; // freopen("d: // 1.text", "r", stdin); // default constructor std::map<std:: string , int > map1; map1[ " something " ] = 69 ; map1[ " anything " ] = 199 ; map1[ " that thing " ]