CStdioFile对文件的某一行进行修改

来源:互联网 发布:上海潘多网络 编辑:程序博客网 时间:2024/05/21 21:02
举个例子,有一文本文件test.txt如下:
192.168.1.1:1,60.000,60.000
192.168.1.1:2,60.000,60.000
192.168.1.1:3,60.000,60.000
192.168.1.1:5,60.000,60.000
192.168.1.1:21,60.000,60.000
192.168.1.1:34,60.000,60.000
192.168.1.1:35,60.000,60.000
192.168.1.1:66,60.000,60.000
192.168.1.1:123,60.000,60.000

192.168.1.1:234,60.000,60.000



我想找到192.168.1.1:21这行,并将其后面的值改为40.000,40.000,即这行值变为“192.168.1.1:21,40.000,40.000”

CStdioFile file;

file.Open(L"F:myfile.txt",CFile::modeReadWrite);
CString str;
while(true){
file.ReadString(str);
if(str.Left(str.Find(L",",0))==CString(L"192.168.1.1:21")){
file.Seek(-2-str.GetLength(),CFile::current);
file.Write("192.168.1.1:21,90.000,90.000\n",strlen("192.168.1.1:21,40.000,40.000\n"));
break;
}
}
file.Close();

0 0
原创粉丝点击