WINCE STL使用回忆
来源:互联网 发布:mac粉底液nc20 编辑:程序博客网 时间:2024/05/17 22:24
好久木有用STL的东东了,现在弄几个经常需要注意的地方
1:MAP插入数据
///##########################
#include <map>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
#define TSTRING std::wstring
//////#########################
BOOL Cwince_stl_map_testDlg::OnInitDialog()
{
CDialog::OnInitDialog();
map<int, wstring> mapStudent;
pair<map<int, wstring>::iterator, bool> Insert_Pair;
//
CString II=L"我和你";
CString III=L"心连心";
TSTRING strValuehmjhmjII = (TSTRING ) II;
TSTRING strValuehmjhmjIII = (TSTRING ) III;
//Insert_Pair = mapStudent.insert(pair<int, TSTRING>(1, strValuehmjhmjII));
//mapStudent.insert(pair<int, wstring>(2, strValuehmjhmjIII));
mapStudent.insert(map<int,wstring>::value_type (1, strValuehmjhmjII));
mapStudent.insert(map<int,wstring>::value_type (2, strValuehmjhmjIII));
Insert_Pair = mapStudent.insert(map<int,wstring>::value_type (2, strValuehmjhmjIII));//这个用来判断MAP插入对象是否成功,很有用,以前竟然没有用过,悲催
if(Insert_Pair.second == true)
{
RETAILMSG(TRUE, (TEXT("==cha ru cheng gong ==\r\n")));
}
else
{
RETAILMSG(TRUE, (TEXT("==cha ru shi bai ==\r\n")));
}
map<int, wstring>::iterator iter;
for(iter = mapStudent.begin(); iter != mapStudent.end(); iter++)
{
RETAILMSG(1,(L"jiexishijian1===== %d\r\n" ,(iter->first) ));
RETAILMSG(1,(L"jiexishijian2===== %s\r\n" ,(iter->second).c_str() ));
// RETAILMSG(TRUE, (TEXT("==555==\r\n")));
// RETAILMSG(1,(L"jiexishijian===== %s\r\n" ,mapStudent[0].c_str() ));
//RETAILMSG(1,(L"jiexishijian1===== %s\r\n" ,mapStudent[1].c_str() ));
//RETAILMSG(1,(L"jiexishijian2===== %s\r\n" ,mapStudent[2].c_str() ));
}
int nSize = mapStudent.size();
RETAILMSG(1,(L"mapStudent.size===== %d\r\n" ,nSize ));
return TRUE; // return TRUE unless you set the focus to a control
}
//###################################MAP插入一个结构体
//////#########################
struct SourceKey {
long nUserId;
int iSence;
};
bool operator==(SourceKey& a,SourceKey& b) {
if ((a.nUserId == b.nUserId) && (a.iSence == b.iSence)) {
return true;
}
return false;
}
bool operator<(const SourceKey& a,const SourceKey& b)
{
return a.nUserId < b.nUserId;
}
//###################
///////////////////////
void Cwince_stl_map_testDlg::OnBnClickedButton1()
{
map<int, SourceKey> mapStudent;
map<int, SourceKey>::iterator iter;
pair<map<int, SourceKey>::iterator, bool> Insert_Pair;
SourceKey key1;
SourceKey key2;
key1.nUserId = 1221;
key1.iSence = 1;
key2.nUserId = 122222;
key2.iSence = 2;
mapStudent.insert(make_pair(1, key1));
mapStudent.insert(make_pair(2, key2));
mapStudent.insert(make_pair(3, key2));
for(iter = mapStudent.begin(); iter != mapStudent.end(); iter++)
{
RETAILMSG(1,(L"shan chu zhi hou ===== %d\r\n" ,(iter->first) ));
RETAILMSG(1,(L"shan chu zhi hou2===== %d\r\n" ,(iter->second).nUserId ));
}
}
//###################################################
2:STL MAP插入结构体
- struct A{
- string name;
- double value;
- };
- class U{
- public:
- map<int, A> param;
- ....................
- void setParam(int, A);
- ..................
- };
- void U:: setParam(int s, A pa){
- param.insert(pair<int,struct A>(s, pa)); //注意主要关注这个,如果没有这个强制STUCT就出问题了。。。。
- }
- class M{
- public:
- U multi[20];
- ...................................
- void initM();
- };
- void M:: initM(){
- for(int i=0; i<20; i++){
- string someStr;
- A initPa = {someStr, 0.0};
- multi[i].setParam(i, initPa);
- }
- }
- WINCE STL使用回忆
- WINCE 使用STL Vector
- wince下使用STL出现4786编译警告
- 6410 wince IROM引导SD升级 回忆
- 技术使用的一些回忆
- 回忆
- 回忆
- 回忆
- 回忆
- 回忆....
- 回忆
- 回忆。。
- 回忆
- 回忆
- 回忆
- 回忆
- 回忆
- 回忆
- HTML5新增标签<audio>简单的使用
- Android获取基站坐标代码
- 史上最杯具应用: 城门下的池鱼——餐厅店长助手-食神摇摇
- CDOJ1208 作为求双连通分量的模板
- 在vi按了ctrl+s后
- WINCE STL使用回忆
- linux IO重定向
- servlet笔记06:单例问题
- 五、信号处理 alarm
- 搜索引擎收录提交链接大全
- Selenium用户指南 - 第六章 Selenium 1 (Selenium RC)[3]
- servlet笔记07:web.xml中的通配符
- Selenium用户指南 - 第六章 Selenium 1 (Selenium RC)[4]
- 《狙击手:幽灵战士》屏幕发白之解决