void C加字符到txtDlg::OnBnClickedButton4()
{
CString str;
try
{
CFile file1(_T("D:\11\1.txt"), CFile::modeRead);
DWORD txtSize = (DWORD)file1.GetLength();
char* buf = new char[txtSize + 1];
memset(buf, 0, sizeof(char)* (txtSize + 1));
file1.Read(buf, txtSize);
str = CString(buf);
delete[] buf;
buf = NULL;
file1.Close();
}
catch (CException* e)
{
e->ReportError();
e->Delete();
}
MessageBox(str); //能讀取
try
{
CFile f(_T("D:\\11\\0.txt"), CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate);
f.SeekToEnd();
CString a =_T("D:\\11\\0.txt ")+ str; //但無法寫入
f.Write(a, a.GetLength() * sizeof(TCHAR));
f.Close();
}
catch (CException* e)
{
e->ReportError();
e->Delete();
}
}
那也應該是strcat(buf, (char *)str);
你追加的是文件名而不是文件內容