ofstream ofsTianwangFile(ofsName.c_str(),ios::app|ios::binary); if(!ofsTianwangFile){ cerr << "cannot open " << ofsName << "for output" << endl; return (-1); } char strDownloadTime[128]; time_t tDate; memset(strDownloadTime,0,128); time(&tDate); strftime(strDownloadTime, 128,"%a, %d %b %Y %H:%M:%S GMT", gmtime(&tDate)); ofsTianwangFile << "version: 1.0\n"; //if( iPage.m_sLocation.empty() == true ){ if( iPage.m_sLocation.length() == 0 ){ ofsTianwangFile << "url: " << iUrl.m_sUrl; }else{ ofsTianwangFile << "url: " << iPage.m_sLocation; ofsTianwangFile << "\norigin: " << iUrl.m_sUrl; } ofsTianwangFile << "\ndate: " << strDownloadTime; if( mapCacheHostLookup.find(iUrl.m_sHost) == mapCacheHostLookup.end() ){ ofsTianwangFile <<"\nip: " << iUrl.m_sHost; }else{ ofsTianwangFile <<"\nip: " << ( *(mapCacheHostLookup.find(iUrl.m_sHost)) ).second; } ofsTianwangFile << "\nlength: " << iPage.m_nLenContent + iPage.m_nLenHeader + 1 << "\n\n" << iPage.m_sHeader << "\n"; ofsTianwangFile.write( iPage.m_sContent.c_str(), iPage.m_nLenContent); ofsTianwangFile << "\n"; ofsTianwangFile.close();