[置顶] C++代码记录1--map

#include <iostream>
#include <unistd.h>
#include <string.h>
//#include "MapReader.h"
#include <map>
#include <string>
using namespace std;
class test
{
public:
	test(int id,string strtest)
	{
		nId = id;
		str = strtest;
		str_buf = new char[50];
		cout << sizeof(str.c_str()) <<endl;
		strncpy(str_buf,str.c_str(),strlen(str.c_str()));
	}
public:
	int nId;
	string str;
    char * str_buf; 
};
int main()
{
	 map<int,test*> myMap;
	 test * tt = new test(1002,"sssssssssssssd");
	 test * tt1 = new test(1003,"sssssssssssssd");
	 myMap.insert(map<int,test*>::value_type(tt->nId,tt));
	
	 myMap[tt1->nId] =tt;
	 map<int,test*>::iterator it = myMap.find(1002);
	 if(it!=myMap.end())
	 {
		 if(it->second!=NULL)
		 {
			 cout << myMap[1002]->str <<endl;
			 cout << myMap[1002]->str_buf <<endl;
		 }
	 }
	 cout << myMap[1003]->str_buf <<endl;

	/* for(it=myMap.begin();it!=myMap.begin();it++)
	 {
		 cout << it->second.str <<endl;
	 }*/

	/*for(int i=0;i<=10000;i++)
	{
		CMapReader mapReader = CMapReader("dead1.map");
		mapReader.initMapFile();
		int w = mapReader.getWidthFromMap();
		int h = mapReader.getHeightFromMap();
		int k = mapReader.getAlphaFromMap(700,526);
		cout <<"before digHole" << "  " << "i=" <<i <<"  " << k <<endl; 
		for (int j=0;j<400;j++)
		{
		int k = mapReader.digHole("crater.map",509+2*j,526);
		usleep(5);
		}
		k = mapReader.getAlphaFromMap(700,526);
		cout <<"after digHole" << "  " << i << k <<endl; 
		sleep(1);
		cout <<"dddd" <<w <<" "<<h<<endl;
	}*/
	
}

你可能感兴趣的:([置顶] C++代码记录1--map)