#include <iostream> #include <string> #include <boost/regex.hpp> #include <fstream> #include <afx.h> #import "C:/Program Files/Common Files/System/ado/msado15.dll" no_namespace rename("EOF","rsEOF") int main() { CoInitialize(NULL); _ConnectionPtr pConn(__uuidof(Connection)); pConn->ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=SitesInfo.mdb;Persist Security Info=False"; try { pConn->Open("","","",adConnectUnspecified); } catch(_com_error e) { // MessageBox(e.Description()); } CString strSql; CString townname; CString cityname; CString provincename; // FILE *pFile=fopen("join.txt","r"); char *pBuf; fseek(pFile,0,SEEK_END); int len=ftell(pFile); pBuf=new char[len+1]; rewind(pFile); fread(pBuf,1,len,pFile); pBuf[len]=0; fclose(pFile); // //var p1 = new provincesList("CN","2361","辽宁"); //c = new provinceCN("西藏","3300","那曲") //c.addCity("3301","那曲县") //c.addCity("3302","嘉黎县") std::string regstr = "(//(/"([A-Z]{2})/",/"[0-9]{4}/",/"([^(0-9a-zA-Z///, )]+?)/"//)//)){1}"; // "//W*c//.addCity//(/"[0-9]{4}/",/"([^(0-9a-zA-Z///, )]+?)/"//)"; boost::regex expression(regstr); std::string str = pBuf; boost::smatch what; std::string::const_iterator start = str.begin(); std::string::const_iterator end = str.end(); while( boost::regex_search(start, end, what, expression) ) { std::string msg1(what[1].first, what[1].second); std::string msg2(what[2].first, what[2].second); std::string msg3(what[3].first, what[3].second); // std::string msg4(what[4].first, what[4].second); std::cout<<msg1.c_str()<<" "<<msg2.c_str()<<" "<<msg3.c_str()<<std::endl; // townname=msg4.c_str(); if(msg1!="") { // cityname=msg3.c_str(); provincename=msg3.c_str(); } strSql.Format(_T("insert into Province (ProvinceName) values ('%s')"),provincename); BSTR sql=strSql.AllocSysString(); pConn->Execute(sql,NULL,adCmdText); start = what[3].second; } // pConn->Close(); // return 0; }