随笔分类 -  STL

摘要:stl之map erase方法的正确使用STL的map表里有一个erase方法用来从一个map中删除掉指令的节点eg:map<string,string> mapTest;typedef map<string,string>::iterator ITER;ITER iter=mapTest.find(key);mapTest.erase(iter);像上面这样只是删除单个节点,map的形为不会出现任务问题,但是当在一个循环里用的时候,往往会被误用,那是因为使用者没有正确理解iterator的概念.像下面这样的一个例子就是错误的写法,eg.for(ITER iter=ma 阅读全文
posted @ 2013-04-22 14:45 byfei 阅读(108) 评论(0) 推荐(0) 编辑
摘要:#include<map>#include<iostream>#include <string>using namespace std;int main(){ map<int,map<int,string> >multiMap; //对于这样的map嵌套定义, map<int, string> temp; //定义一个map<int, string>变量,对其定义后在插入multiMap temp[90] = "hi"; temp[100] = "maxi"; multi 阅读全文
posted @ 2013-01-17 10:40 byfei 阅读(595) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>#include <vector>#include <map>using namespace std;struct LevelAwardItems{ int m_ItemID; int m_Num; int m_KeyWorld;};typedef vector<LevelAwardItems> templateItem;templateItem m_VectItem;map <int, templateItem>m_MapLevelAward;void main(){ for(int j=0;j 阅读全文
posted @ 2012-10-24 10:01 byfei 阅读(483) 评论(0) 推荐(0) 编辑
摘要:当执行大数据量的调用push_back()的时候,记住要调用vector::reserve()。研究了vector和deque在插入数据的情况。通过这些假设,我们可以看出deque分配的空间是预先分配好的,deque维持一个固定增长率,在vector实验中我们考虑到应该调用vecor::reserve().然后在下面这个例子验证了我们的假设,在使用vector的时候调用reserve()能够膀子我们预先分配空间,这将是vector一个默认选择的操作。当你分配很多内存单元的时候,记住使用deque回收内存要比vector消耗时间多。探讨了vector和deque在回收非邻接内存块上的不同,分别证 阅读全文
posted @ 2012-07-19 21:03 byfei 阅读(141) 评论(0) 推荐(0) 编辑
摘要:typedef map<int, int> templatemap;templatemap AllScoreSort; for(int i=10000;i<10010;i++) AllScoreSort[i]=i+1; for (templatemap::iterator iter = AllScoreSort.begin(); iter!= AllScoreSort.end(); iter++){int nRoleID = iter->first;int nScore = iter->second;if (10005 < nRoleID){//AllSco 阅读全文
posted @ 2012-06-21 16:42 byfei 阅读(186) 评论(0) 推荐(0) 编辑
摘要:#include <vector>#include <iostream>#include "compacket.h"#include <map>using namespace std;struct Activity{int m_nStep;int m_nCount;Activity():m_nStep(1),m_nCount(0){}Activity(const int nStep,const int nCount):m_nStep(m_nStep = nStep),m_nCount(m_nCount = nCount){}};int m 阅读全文
posted @ 2012-05-18 17:01 byfei 阅读(189) 评论(0) 推荐(0) 编辑
摘要:#include <vector>#include <iostream>#include <iterator>using namespace std;int main(){int N = 2, M = 3;vector<vector<int> > Matrix(N, vector<int> (M, 0));ostream_iterator<int> os(cout, " ");Matrix[0][2] = 4;//交换矩阵的两行Matrix[0].swap(Matrix[1]);//交换矩阵 阅读全文
posted @ 2012-05-14 14:49 byfei 阅读(1372) 评论(0) 推荐(0) 编辑
摘要:#include <stdio.h>#include <string>#include <stdlib.h>#include <iostream>#include <map>#include <vector>using namespace std;typedef map<int, int> templatemap;templatemap ScoreSort;int GetPOS(templatemap Sort, int nRoleID){if (Sort.find(nRoleID) == Sort.end() 阅读全文
posted @ 2012-05-02 21:52 byfei 阅读(243) 评论(0) 推荐(0) 编辑
摘要:#ifndef CBIGBOSS_H_#define CBIGBOSS_H_#include <time.h>#include <map>using namespace std;class CBigBoss {public:typedef map<int, int> templatemap;templatemap BossSort;bool Insert(int nRoleID,int nHurtBlood);bool Updata(int nRoleID,int nHurtBlood);bool Remove(int nRoleID);}#endifboo 阅读全文
posted @ 2012-03-08 23:11 byfei 阅读(226) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>#include <string.h>#include <stdio.h>#include <map>using namespace std;class MapTemplate{public:typedef map <int ,string> templatemap;templatemap testmap;templatemap::iterator Find(int nID){return testmap.find(nID);}string GetElement(int nID){template 阅读全文
posted @ 2011-10-18 17:59 byfei 阅读(108) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>#include <string.h>#include <stdio.h>#include <map>using namespace std;typedef map <int ,string> templatemap;templatemap testmap;templatemap::iterator Find(int nID){return testmap.find(nID);}string GetElement(int nID){templatemap::iterator iter = Find 阅读全文
posted @ 2011-10-18 17:34 byfei 阅读(115) 评论(0) 推荐(0) 编辑
摘要:一. vector1.声明: 一个vector类似于一个动态的一维数组。 vector<int> a; //声明一个元素为int类型的vector a vectot<MyType> a; //声明一个元素为MyType类型的vector a 这里的声明的a包含0个元素,既a.size()的值为0,但它是动态的,其大小会随着数据的插入 和删除改变而改变。 vector<int> a(100, 0); //这里声明的是一已经个存放了100个0的整数vector2.向量操作常用函数: size_t size(); // 返回vector的大小,即包含的... 阅读全文
posted @ 2011-09-23 17:35 byfei 阅读(199) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>#include <vector>using namespace std;struct NODE{int m_nRoleID;int m_nScore;string m_strROleName;NODE() :m_nRoleID(1), m_nScore(0),m_strROleName("byfei"){}NODE(const int nRoleID, const int nScore,const string strRoleName) :m_nRoleID(nRoleID), m_nScore(nScore) 阅读全文
posted @ 2011-09-21 10:33 byfei 阅读(748) 评论(0) 推荐(0) 编辑