main.cpp

来自「C++ Source code from a tutorial」· C++ 代码 · 共 46 行

CPP
46
字号
#include <iostream>
#include <stdlib.h>
#include <map>
#include <string>

using namespace std;

class MyClass {
public:
    string Name;
};

class MyLess {
public:
    bool operator()(const MyClass &x, 
    const MyClass &y) const {
        return x.Name < y.Name;
    }
};


int main(int argc, char *argv[])
{
    map<int,int> A;
    A[0] = 1;
    A[1] = 2;
    A[2] = 4;
    
    map<int,int,less<int> > B;
    B[0] = 10;
    B[1] = 20;
    B[2] = 40;
    
    map<MyClass, MyClass, MyLess> C;
    MyClass key1 = {"Harold"};
    MyClass value1 = {"123"};
    MyClass key2 = {"Lloyd"};
    MyClass value2 = {"952"};
    C[key1] = value1;
    C[key2] = value2;
    cout << C[key2].Name << endl;
    
    system("PAUSE");	
    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?