#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(NULL,e.Description(),_T(""),MB_ICONWARNING); } /// CString cate1,cate2,cate3; CString strSql; /// std::string filename="product.txt"; CString strTemp; FILE *pFile=fopen(filename.c_str(),"r"); CStdioFile file(pFile); /// std::string regstr1 =".*?//(/'-?//d+/'//W*/'(/[^(/')]+?)/'//)"; std::string regstr2 =".*?//(topCat//W*/'-?//d+/'//W*/'([^(/')]+?)/'//)"; std::string regstr3 =".*?//(sCat//W*/'-?//d*/'//W*/'([^(/')]+?)/'//)"; boost::regex expression1(regstr1); boost::regex expression2(regstr2); boost::regex expression3(regstr3); /// int Index1=0,Index2=0; while(file.ReadString(strTemp)) { CString etac1,etac2,etac3; etac1=cate1; etac2=cate2; etac3=cate3; char *pBuf=new char[strTemp.GetLength()+1]; sprintf(pBuf,"%S",strTemp); boost::cmatch what; if( boost::regex_match(pBuf, what, expression1)) { std::cout << what[1].str() << std::endl; std::string msg(what[1].first,what[1].second); cate1=msg.c_str(); Index1=0; Index1+=1; cate2=""; cate3=""; /*MessageBox(NULL,cate1,_T(""),MB_OK);*/ }else { if( boost::regex_match(pBuf, what, expression2)) { std::cout <<" "<< what[1].str() << std::endl; std::string msg(what[1].first,what[1].second); cate2=msg.c_str(); Index1+=1; Index2=0; Index2+=1; cate3=""; } else { if( boost::regex_match(pBuf, what, expression3)) { std::cout <<" "<< what[1].str() << std::endl; std::string msg(what[1].first,what[1].second); cate3=msg.c_str(); Index1+=1; Index2+=1; } } } if(etac1!=cate1||etac2!=cate2||etac3!=cate3) { if(Index1==2||Index2==2) { strSql.Format(_T("update ProductCategory set Cate1CN='%s',Cate2CN='%s',Cate3CN='%s' where ID=(select top 1 id from ProductCategory order by id desc)"),cate1,cate2,cate3); } else { strSql.Format(_T("insert into ProductCategory (Cate1CN,Cate2CN,Cate3CN) values ('%s','%s','%s')"),cate1,cate2,cate3); } BSTR sql=strSql.AllocSysString(); pConn->Execute(sql,NULL,adCmdText); } delete[] pBuf; } fclose(pFile); pConn->Close(); return 0; }