目的是要实现每次调用下面代码就在文本文件open.txt中写入一行字符,然后换行,字符定义在theword里面,每次内容都不一样,但长度一样(90个字符),可是执行的时候,总是只保存着最后一次写入的一行,以前的都被覆盖了,请问高手怎么该代码啊,谢谢! CString filename="g:\\open.txt";
CFile file((LPCTSTR) filename,CFile::modeCreate|CFile::modeReadWrite);
CString nextline;
nextline.Format("\n");
CString strBuf=theword+nextline;
file.SeekToBegin();
file.Write((void*)(LPCTSTR)strBuf,strBuf.GetLength());
file.Close();
CFile file((LPCTSTR) filename,CFile::modeCreate|CFile::modeReadWrite);
CString nextline;
nextline.Format("\n");
CString strBuf=theword+nextline;
file.SeekToBegin();
file.Write((void*)(LPCTSTR)strBuf,strBuf.GetLength());
file.Close();
解决方案 »
- 智能指针的问题,谁能解释一下?
- 免杀问题求助?
- 现在用什么开发windows下的驱动?
- 请高手帮忙解决vc下smtp发送邮件的问题!
- 谁有DevPartner.Studio.Professional.Edition.8.0
- listen 的socket close前有没有必要shutdown()?
- 请问: ......tear-off interface ...... 是什么意思?
- 求助Template-Based Class:CArray<CPoint,CPoint> m_pointArray;
- check box的问题????
- 关于成组的Radio Button的使用问题,为什么交换不了数据?
- 迷途的羔羊(小鸟对VC的迷惑)
- 高分求教:VC中怎么编写一个 WORD转换成 TIFF文件的驱动程序
DWORD dwFlag=CFile::modeReadWrite;
if(_access(filename,0)!=0)
{
dwFlag|=CFile::modeCreate;
}
CFile file((LPCTSTR) filename,dwFlag);
CString nextline;
nextline.Format("\n");
CString strBuf=theword+nextline;
file.SeekToBegin();
file.Write((void*)(LPCTSTR)strBuf,strBuf.GetLength());
file.Close();
file.Write((void*)(LPCTSTR)strBuf,strBuf.GetLength());
每次都从文劲头开始写入当然覆盖了上次写入的内容!
{
FILE* debugFile = fopen(szFileName, "a"); if(debugFile == NULL)
return; va_list argList;
va_start(argList, string); fprintf(debugFile, "%02d:%02d:%02d ", tNow.GetHour(), tNow.GetMinute(), tNow.GetSecond()); vfprintf(debugFile, string, argList);
fprintf(debugFile, "\r\n"); fflush(debugFile);
fclose(debugFile);
}
file.Write(...);
不能用啊
error C2065: '_access' : undeclared identifier