国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

文章標題

2019-11-08 20:04:17
字體:
來源:轉載
供稿:網友

OperationFile.h // COperationFile.h : header file //

PRagma once

include

include

include

using namespace std;

class COperationFile { // Construction public: COperationFile(); ~COperationFile();

public: void OnFileFilling(In CString strFilePath , In BOOL bIsAddress=TRUE); /* 函數功能:刪除重復的字符串(最簡單的刪除方法,有時間修改為二分法排序刪除) * vctStrSaveFileData:輸入輸出參數 */ void deleteRepeatString(Inout vector& vctStrSaveFileData); void SetFileReadWrite( In CString cstrFileFullPath ); string CString2string(CString &strSrc); /* 函數功能:處理輸入字符串,去掉與命令無關的信息 * strSrc:輸入源字符串 * strReqHeader:“問”字符串 * bIsAns:是否為“回”字符串 * 返回值:處理后的字符串,使用vector的原因是一些回答命令會超過7個字符,這個時候需要把超過7個字符的命令拆分為不能大于7個字符的命令串 */ vector DealString(In CString strSrc, In CString strReqHeader, BOOL bIsAns=FALSE); };

OperationFile.cpp // COperationFile.cpp : implementation file //

include “stdafx.h”

include “OperationFile.h”

define MAX_STRING_COUNT 400

define Ans _T(“Ans:”)

define REQ _T(“Req:”)

COperationFile::COperationFile( ) { }

COperationFile::~COperationFile( ) { }

void COperationFile::OnFileFilling(In CString strFilePath, In BOOL bIsAddress/=TRUE/) { // TODO: Add your control notification handler code here int nRet=0; CString strReq=_T(“”); vector vctDealString; vector vctStrSaveFileData;

CStdioFile stdioFile;CFileException e;nRet = stdioFile.Open(strFilePath, CFile::modeNoTruncate | CFile::modeReadWrite | CFile::shareDenyNone, &e );if (!nRet){ AfxMessageBox(_T("文件打開失敗!!!")); return;}stdioFile.SeekToBegin();CString strTemp;while (stdioFile.ReadString(strTemp)){ if (-1 != strTemp.Find(_T("Req:")) ) { vctDealString = DealString(strTemp,_T("")); strReq=vctDealString[0]; continue; } if (-1 == strTemp.Find(_T("Ans:")) ) { continue; } if (strReq.GetLength() > 0 ) { vctDealString = DealString(strTemp, strReq.Mid(0, 14), TRUE); vctStrSaveFileData.push_back(strReq); for (int k=0; k < vctDealString.size(); k++) { vctStrSaveFileData.push_back(vctDealString[k]); } }}stdioFile.Flush();stdioFile.Close();deleteRepeatString(vctStrSaveFileData);strFilePath+=_T(".txt");CStdioFile newFile;newFile.Open(strFilePath,CFile::modeCreate | CFile::modeWrite , &e );if (!nRet){ AfxMessageBox(_T("文件創建失敗!!!")); return;}for (int k = 0; k < vctStrSaveFileData.size(); k++){ if ( !vctStrSaveFileData[k].IsEmpty() ) { newFile.WriteString(vctStrSaveFileData[k]); newFile.WriteString(_T("/r/n")); if ( vctStrSaveFileData[k+1].Find(_T("Req:")) != -1 ) { newFile.WriteString(_T("/r/n")); } } }newFile.Flush();newFile.Close();AfxMessageBox(_T("文件處理完成"));

}

vector COperationFile::DealString(In CString strSrc, In CString strReqHeader, BOOL bIsAns/=FALSE/) { int nValidCmd; vector vctStrSaveCmd; CString strTemp=strSrc, strAnsHeader=_T(“”), strAnsBody=_T(“”); CString x20x09=_T(” Receive”); if (!bIsAns) strTemp=strTemp.Mid(0, strTemp.Find(x20x09));

ifdef _DEBUG0

if (strTemp.Find(_T("19 02 8F")) != -1 ){ AfxMessageBox(_T("發現要找的字符串!!!"));}

endif

strTemp.Delete(5, 5);strAnsHeader=strTemp.Mid(0, 12);strAnsHeader.Insert(5, _T(" "));strAnsBody=strTemp.Mid(12, strTemp.GetLength());nValidCmd = strAnsBody.GetLength()/3;if (nValidCmd <= 7){ for (int k = 0; k < 7- nValidCmd; k++) { strAnsBody+= _T("00 "); } strAnsHeader.AppendFormat(_T("08 %02d "), nValidCmd); vctStrSaveCmd.push_back( strAnsHeader +strAnsBody);}else{ int nRemainder=0, nCounter=21, nQuotient; nRemainder = (nValidCmd-6)%7; nQuotient=(nValidCmd-6)/7; if (nRemainder>0) { nRemainder=7-nRemainder; nQuotient+=1; } for (int k = 0; k < nRemainder; k++) { strAnsBody+=_T("00 "); } strTemp.Format(_T("08 1%01X %02X "), nValidCmd&0xF00, nValidCmd&0xFF); vctStrSaveCmd.push_back( strAnsHeader+strTemp+strAnsBody.Mid(0, 18)); vctStrSaveCmd.push_back(strReqHeader+_T("08 30 00 00 00 00 00 00 00")); strAnsHeader.SetAt(4, '1'); strAnsHeader.SetAt(5, 'N'); strAnsBody=strAnsBody.Mid(18); //21 22 23 24... for (int k=0; k < nQuotient; k++) { if ( k == nQuotient-1) { strAnsHeader.SetAt(4, ' '); strAnsHeader.SetAt(5, ' '); } strTemp.Format(_T("08 %02d "), nCounter++); vctStrSaveCmd.push_back(strAnsHeader+strTemp+strAnsBody.Mid(0, 21)); strAnsBody=strAnsBody.Mid(21); }} return vctStrSaveCmd;

}

void COperationFile::deleteRepeatString(vector& vctStrSaveFileData) { // map

ifdef _UNICODE

int nLength = strSrc.GetLength();int nBytes = WideCharToMultiByte(CP_ACP,0,strSrc,nLength,NULL,0,NULL,NULL);char* VoicePath = new char[ nBytes + 1];memset(VoicePath,0,nLength + 1);WideCharToMultiByte(CP_ACP, 0, strSrc, nLength, VoicePath, nBytes, NULL, NULL); VoicePath[nBytes] = 0;strTarge = VoicePath;

else

strTarge = strSrc.GetBuffer(0);

endif

return strTarge;

}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 扬中市| 新乐市| 台东县| 大同市| 仲巴县| 扶绥县| 文山县| 莱州市| 无锡市| 浑源县| 金塔县| 上蔡县| 永善县| 巫山县| 吐鲁番市| 沛县| 原平市| 浪卡子县| 长子县| 惠安县| 治多县| 吕梁市| 济阳县| 文昌市| 阿克陶县| 七台河市| 奉节县| 桐柏县| 灵宝市| 山西省| 门头沟区| 万安县| 宝应县| 西宁市| 高青县| 蒙山县| 华亭县| 中山市| 宁夏| 富锦市| 凤山县|