高分求救,关于写文件的问题。
开发环境:VC6.0+Windows XP
代码如下:
#include <stdio.h>
#include <string>
#include <windows.h>
using namespace std;
void main()
{
while( true )
{
string sTest = "hellohellohellohellohellohellohellohelloh
ellohellohellohellohellohellohellohello";
FILE *fp = NULL;
fp = fopen("d:\\test.txt", "a");
if ( fp!=NULL )
{
fprintf(fp, "%s\n", sTest.c_str());
fclose(fp);
}
Sleep(1);
}
}
出现问题:这段代码有时候会出错,在fprintf上断言会失败(也就是标红的代码行)。为什么?解决方法?
谢谢各位了先!