c++ - 字符串->结构CMap

标签 c++ visual-c++ mfc

我的要求是给定一个字符串作为映射的键,我应该能够检索一个结构。

有人可以为此发布示例代码吗?

例如:

struct
{
int a;
int b;
int c;
}struct_sample;

string1 -> strcut_sample

最佳答案

CMap<CString,LPCTSTR, struct_sample,struct_sample> myMap;

struct_sample aTest;
aTest.a = 1;
aTest.b = 2;
aTest.c = 3;
myMap.SetAt("test",aTest);
...

    struct_sample aLookupTest;
    BOOL bExists = myMap.Lookup("test",aLookupTest); //Retrieves the 
                             //struct_sample corresponding to "test".

示例来自 MDSN有关 CMap 的更多详细信息。

关于c++ - 字符串->结构CMap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/848551/

相关文章:

c++ - 关于 std::hash 实现的公平假设

c++ - MSVC 2017 - 错误 - 如何将模板类 X 的模板成员函数声明为嵌套类 X::Y 的友元

c++ - 监听进程开始和结束

c++ - 如何绘制禁用图标

c++ - 在 Mysql ODBC 中禁用 GUI

c++ - 非常大的枚举器(> 64 位类型)

c++ - Switch 语句 C++ 的问题

c++ - 下一个标准可以改变内部STL容器结构吗

c++ - 为什么 STL 容器优于 MFC 容器?

c++ - 在 MFC 中禁用 CheckedListBox 中的项目