在網上找了許久也未找到一個從CEdit控件到文件的格式化輸出方法,下爲一種,有些麻煩。希望拋磚引玉。
BOOL CPro71Dlg::SaveFile(CString strPath)
{
CString str;
char buf[255];
int nCount=m_cEdit.GetLineCount ();
CStdioFile file;
file.Open (strPath,CFile::modeCreate|CFile::modeWrite);
for (int i=0;i<nCount;i++)
{
ZeroMemory (buf,255);
m_cEdit.GetLine (i,buf,255);
// MessageBox (buf);
file.WriteString (buf);
file.WriteString ("/n"); //保持格式
}
file.Close ();
}
打開時的代碼:
file.Open (m_strPath,CFile::modeReadWrite);
// VERIFY (file);
while (file.ReadString (str1))
{
str+=str1;
str+="/r/n"; //保持格式
}
file.Close ();