#include/************************************************************************//* 一个io模版.来实现对结构体等对象的存储和加载 struct stCityInfo { char cityName[255]; POINT A; POINT B; }; IOPack io; int _tmain(int argc, _TCHAR* argv[]) { io.LoadFromFile("city.dat"); stCityInfo info; strcpy(info.cityName,"武汉"); info.A.x=111; info.A.y=222; info.B.x=333; info.B.y=444; printf("%d \n",io.m_List.size()); } simawei@qq.com 2012*//************************************************************************/template class IOPack{public: IOPack(void){ } ~IOPack(void){ } bool LoadFromFile(const char* filename) { printf("InitFromFile [%s]\n",filename); FILE* f=fopen(filename,"rb"); if (NULL==f) { printf("[line:%d][%s] open err\n",__LINE__,__FUNCTION__); return false; } int totalsize = GetFileSize(filename); if (totalsize==-1) { return false; } int readoffset=0; while(readoffset m_List;private: long GetFileSize(const char* filename ) { FILE* fp = fopen( filename, "r" ); if (fp==NULL) return -1; fseek( fp, 0L, SEEK_END ); int s=ftell(fp); fclose(fp); return s; }};