读书人

遇到fopen的一个有关问题,紧

发布时间: 2012-02-29 16:44:11 作者: rapoo

遇到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 做个转换

读书人网 >C++ Builder

热点推荐