1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > VC++ 删除当前读取行 代码

VC++ 删除当前读取行 代码

时间:2019-03-08 14:09:46

相关推荐

VC++  删除当前读取行 代码

操作Text,要删除当前读取的行。(VC 文件操作DEMO)

我想到两种方法:

1.生成临时文件 读一行 写进去 跳过要删除的行

2.全部读入内存 删除 然后写回txt文件

第一种方法上代码:

View Code

1 void CPoint7Dlg::OnBnClickedButton5() 2 { 34CStringstrPathName; 5GetModuleFileName(NULL,strPathName.GetBuffer(256),256); 6strPathName.ReleaseBuffer(256); 7int nPos = strPathName.ReverseFind('\\'); 8strPathName = strPathName.Left(nPos +1); 9 10CStdioFile file;11CString str;12CString firstStr;13CString strFull;14str.Format(strPathName+"Log\\1.txt",g_BasePath);15if (file.Open(_T(str),CFile::modeRead | CFile::typeText))16{17 file.SeekToBegin();18 int i=1;19 while(file.ReadString(str))20 { 21 if(i>1)22 {23strFull+=str+"\n";24 }25 i++;26 } 27 file.Close();28 MessageBox(strFull);29}30else31{32 MessageBox(_T("data1.txt文件打开失败"));33}34 35strPathName; 36GetModuleFileName(NULL,strPathName.GetBuffer(256),256); 37strPathName.ReleaseBuffer(256); 38nPos = strPathName.ReverseFind('\\'); 39strPathName = strPathName.Left(nPos +1);40 41 42str.Format(strPathName+"Log\\1.txt",g_BasePath);43 44if (!file.Open(_T(str),CFile::modeCreate | CFile::modeWrite | CFile::typeText))45{46 MessageBox(_T("未打开文件"));47}48else49{50 file.WriteString(strFull);51 file.Close();52}53 }

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。