怎么读取文本文件的多行,以两个或多个换行结束。谢谢 怎么读取文本文件的多行,以两个或多个换行结束。谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 采用CStdioFile,每次可以读一行:CStdioFile file;file.open(...);CString str;while( file.ReadString( str ) ){ .....} CString m_disp,m_end; m_end = _T("\n\n");//两个换行符 myfile.Open("XX.txt",CFile::modeRead);//从XX.txt中读入数据 myfile.SeekToBegin(); myfile.Read(m_disp.GetBufferSetLength(myfile.GetLength()),myfile.GetLength()); if (!m_disp.IsEmpty()) { int index = m_disp.Find(m_end); m_disp = m_disp.Right(m_disp.GetLength()-index-4); } UpdateData(false); myfile.Close();该程序可以读任意行中英文字符,直到遇到"\n\n"停止 下面一个程序是读入150个HTML文件,然后为每个文件加上两个链接。读取HTML文件和读取TXT文件一样的。下面程序可用作读取整个文档。只需稍微改动一下。至于以两个或多个换行结束str += "\r\n";执行两次或多次。int count = 0; CString head, end, inshead, insend; head.Format("E:\\0\\download\\luolan\\new\\jjl\\jjl\\jjl"); end.Format(".htm"); insend += "</p><p align=\"center\"><a href=\"../%C6%DA%BF%AF%D4%D3%D6%BE.htm\">回目录</a></p>"; inshead += "<p align=\"center\"><a href=\"../%C6%DA%BF%AF%D4%D3%D6%BE.htm\">回目录</a></p><p>"; for(int i = 10; i < 28; i++) { CFile myfile; CString index, txt, filename = head; index.Format("%d", i); filename += index; filename += end; myfile.Open(filename, CFile::modeReadWrite); DWORD file_size = myfile.GetLength(); myfile.Read(txt.GetBuffer(file_size), file_size); txt.ReleaseBuffer(); int Init1 = txt.Find("<body>"); txt.Insert(Init1+6, inshead); int Init2 = txt.Find("</body>"); txt.Insert(Init2+7, insend); int file_len = txt.GetLength(); myfile.Seek(0, CFile::begin); myfile.Write(txt.GetBuffer(file_len), file_len); myfile.Close(); } MessageBox("OK"); 楼上的zhude同志,你的成员变量怎么记的这么熟悉?还是等用的时候现查MSDN?真是让人羡慕啊:) opencv如何支持baumer相机 80分求助:关于摄像头视频数据的格式和获得及处理 图像折行循环移动的算法. 用什么技术可以禁用桌面右键属性里面的桌面设置 挂接API? DIALOG能做全屏幕吗? 关于IE toolbar的问题 (苦等)要多少分都给你 高手帮忙解答一下,进行fopen()时为什么会不停地产生WM_WINDOWPOSCHANGED. 产生线程的问题?(请大家点评,分析这断代码) 请问如何将菜单放到窗口的右边而不是上面? 如何把一buffer(来自文件,采集卡..)中的位图数据转化为一个HBITMAP,位图句柄 怎么在非模式对话框中控制主界面的静态文本显示
file.open(...);
CString str;
while( file.ReadString( str ) )
{
.....
}
m_end = _T("\n\n");//两个换行符
myfile.Open("XX.txt",CFile::modeRead);//从XX.txt中读入数据
myfile.SeekToBegin();
myfile.Read(m_disp.GetBufferSetLength(myfile.GetLength()),myfile.GetLength());
if (!m_disp.IsEmpty())
{
int index = m_disp.Find(m_end);
m_disp = m_disp.Right(m_disp.GetLength()-index-4);
}
UpdateData(false);
myfile.Close();该程序可以读任意行中英文字符,直到遇到"\n\n"停止
读取HTML文件和读取TXT文件一样的。
下面程序可用作读取整个文档。只需稍微改动一下。
至于以两个或多个换行结束
str += "\r\n";
执行两次或多次。
int count = 0;
CString head, end, inshead, insend;
head.Format("E:\\0\\download\\luolan\\new\\jjl\\jjl\\jjl");
end.Format(".htm");
insend += "</p><p align=\"center\"><a href=\"../%C6%DA%BF%AF%D4%D3%D6%BE.htm\">回目录</a></p>";
inshead += "<p align=\"center\"><a href=\"../%C6%DA%BF%AF%D4%D3%D6%BE.htm\">回目录</a></p><p>";
for(int i = 10; i < 28; i++)
{
CFile myfile;
CString index, txt, filename = head;
index.Format("%d", i);
filename += index;
filename += end; myfile.Open(filename, CFile::modeReadWrite);
DWORD file_size = myfile.GetLength();
myfile.Read(txt.GetBuffer(file_size), file_size);
txt.ReleaseBuffer();
int Init1 = txt.Find("<body>");
txt.Insert(Init1+6, inshead);
int Init2 = txt.Find("</body>");
txt.Insert(Init2+7, insend);
int file_len = txt.GetLength();
myfile.Seek(0, CFile::begin);
myfile.Write(txt.GetBuffer(file_len), file_len);
myfile.Close();
}
MessageBox("OK");