std::pair 问题

cameracanon 2009-03-06 09:48:03
我用VC6.0创建了一个界面,在组合框里的Data写上:L , M1, M2, S。然后又新建一个.h头文件,把与L , M1, M2, S相对应的值,关联起来,如下:
using namespace std;

std::pair<Int,const char*>(0x00100f0f,"L");
std::pair<Int,const char*>(0x05100f0f,"M1");
std::pair<Int,const char*>(0x06100f0f,"M2");
std::pair<Int,const char*>(0x02100f0f,"S");

问:我如何在xxxDlg.cpp文件里调用所对应的值?比如说,我在组合框里选择L,而我实际想用到的是0x00100f0f,并把这个值发送出去。

请高手帮忙,谢谢了!!
...全文
729 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangch_nhcmo 2009-03-07
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 cameracanon 的回复:]
还得包括一个头文件才行: #include <map>

然后修改成
std::map <string, int> mmap;
mmap.insert(std::pair <string, int>("M1", 0x05100f0f));

但是一堆warning C4786 警告问题。

[/Quote]
#pragma warning(disable:4786)
xkyx_cn 2009-03-06
  • 打赏
  • 举报
回复
warning C4786不用管
cameracanon 2009-03-06
  • 打赏
  • 举报
回复
还得包括一个头文件才行: #include <map>

然后修改成
std::map<string, int> mmap;
mmap.insert(std::pair <string, int>("M1", 0x05100f0f));

但是一堆warning C4786 警告问题。
bfhtian 2009-03-06
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 xkyx_cn 的回复:]
使用map来做容器,把需要的值都事先放入容器中,这里可以用后面的字符串做键值:

C/C++ code
map<string, int> mmap;
mmap.insert(pair <string, int>("M1", 0x05100f0f));

// 获取选取的值:
string sSelected = "L";
int nValue;
map<string, int>::iterator it = mmap.find(sSelected);
if (it != mmap.end())
{
nValue = it->second; // nValue就是你想要的值
}
[/Quote]
up
  • 打赏
  • 举报
回复
照你的要求,你应该让string作键值啊,用map做,string存第一个位.
2楼的就可以.
cameracanon 2009-03-06
  • 打赏
  • 举报
回复
我先试一下,谢谢你了
xkyx_cn 2009-03-06
  • 打赏
  • 举报
回复
使用map来做容器,把需要的值都事先放入容器中,这里可以用后面的字符串做键值:

map<string, int> mmap;
mmap.insert(pair <string, int>("M1", 0x05100f0f));

// 获取选取的值:
string sSelected = "L";
int nValue;
map<string, int>::iterator it = mmap.find(sSelected);
if (it != mmap.end())
{
nValue = it->second; // nValue就是你想要的值
}

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧