遇到fopen的一个有关问题,紧
遇到fopen的一个问题,紧急
AnsiString stryear;
FILE *outf;
str1= "abc ";
if (outf= fopen( "e:\\a.txt ", "a "))
{
fprintf(outf, "%s ",str1);
fclose(outf);
}
以上是成功的,但是把 "e:\\a.txt "换成testlog时,就报错.
如下:
AnsiString stryear,testlog;
FILE *outf;
str1= "abc ";
testlog= "e:\\yw.txt ";
if (outf= fopen(testlog, "a "))
{
fprintf(outf, "%s ",str1);
fclose(outf);
}
------解决方案--------------------
testlog
改为 testlog.c_str()
------解决方案--------------------
FILE *fopen(const char *filename, const char *mode);
fopen 函数的参数只能是 char*
所以必须把 AnsiString 做个转换
AnsiString stryear;
FILE *outf;
str1= "abc ";
if (outf= fopen( "e:\\a.txt ", "a "))
{
fprintf(outf, "%s ",str1);
fclose(outf);
}
以上是成功的,但是把 "e:\\a.txt "换成testlog时,就报错.
如下:
AnsiString stryear,testlog;
FILE *outf;
str1= "abc ";
testlog= "e:\\yw.txt ";
if (outf= fopen(testlog, "a "))
{
fprintf(outf, "%s ",str1);
fclose(outf);
}
------解决方案--------------------
testlog
改为 testlog.c_str()
------解决方案--------------------
FILE *fopen(const char *filename, const char *mode);
fopen 函数的参数只能是 char*
所以必须把 AnsiString 做个转换