// TestingandTobe.cpp : 定義控制台應用程式的進入點。//#include "stdafx.h"#include<iostream>#include<map>#include<string>using namespace std;struct student{// virtual void fun(){ 指標指向未知崩潰 void fun(){m_i=0;cout<<"結構體指標調用結構體中的函數測試,...m_i="<<m_i<<endl;}static int m_i;};int student::m_i=0;typedef struct tagStudentInfo { int nID; string strName; }StudentInfo, *PStudentInfo;class sort { public: bool operator() (StudentInfo const &_A, StudentInfo const &_B) const { if(_A.nID < _B.nID) return true; if(_A.nID == _B.nID) return _A.strName.compare(_B.strName) < 0; return false; } };int _tmain(int argc, _TCHAR* argv[]){/*************測試函數指標*************/student *m_p=0;m_p->fun();/*************測試map容器**************///數組方式插入資料map<int,string> mapStudent;mapStudent[3]="student one";mapStudent[1]="student two";mapStudent[2]="student three";map<int,string>::iterator iter;for(iter=mapStudent.begin();iter!=mapStudent.end();iter++){cout<<"insert test..."<<iter->second<<endl;}//測試尋找map<int,string>::iterator iterr;iterr =mapStudent.lower_bound(2);{cout<<"FindTest..."<<iterr->second<<endl;}iterr =mapStudent.upper_bound(2);{cout<<"FindTest..."<<iterr->second<<endl;}pair<map<int,string>::iterator,map<int,string>::iterator>mappair;mappair =mapStudent.equal_range(2);if(mappair.first==mappair.second){cout<<"donot find"<<endl;}else{cout<<"FindTest...find"<<endl;} //insert函數插入資料/*map<int, string> mapStudent; pair<map<int,string>::iterator,bool> Insert_Pair; Insert_Pair=mapStudent.insert(pair<int, string>(1,"student one")); if (Insert_Pair.second == true) { cout<<"Insert Successfully"<<endl; } else { cout<<"Insert Failure"<<endl; } Insert_Pair=mapStudent.insert(pair<int, string>(2,"student two")); if(Insert_Pair.second == true) { cout<<"Insert Successfully"<<endl; } else { cout<<"Insert Failure"<<endl; } map<int, string>::iterator iter; for(iter = mapStudent.begin(); iter != mapStudent.end(); iter++) { cout<<iter->first<<" "<<iter->second<<endl; } *//************************** 測試排序***************************///用學生資訊映射分數 int nSize;map<StudentInfo, int, sort>mapStudentt ; map<StudentInfo, int, sort>::iterator iterrr;StudentInfo studentInfo; studentInfo.nID = 1; studentInfo.strName = "student_one"; mapStudentt.insert(pair<StudentInfo, int>(studentInfo, 90)); studentInfo.nID = 2; studentInfo.strName = "student_two"; mapStudentt.insert(pair<StudentInfo, int>(studentInfo, 80));for(iterrr=mapStudentt.begin();iterrr!=mapStudentt.end();iterrr++)cout<<"Test order..."<<iterrr->second<<endl;return 0;}