我正在尝试打开一个文本文件,将一些数据写入其中,然后在已写入文件的数据的末尾追加一些数据,但这不起作用。任何人都可以帮我找出我的代码的问题吗? 代码片段:
char buffer[]="Write this text to file";
DWORD dwWritten; // number of bytes written to file
HANDLE hFile;
hFile=CreateFile("file.txt",GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
if(hFile==INVALID_HANDLE_VALUE)
{
MessageBox(0,"Could not create/open a file","Error",16);
return 0;
}
WriteFile(hFile,buffer,sizeof(buffer),&dwWritten,0);
DWORD dwPtr = SetFilePointer( hFile, dwWritten, NULL, FILE_END); //set pointer position to end file
WriteFile(hFile,buffer,sizeof(buffer),&dwPtr,NULL);
CloseHandle(hFile);