如何用fwrite写一个AnsiString字符串到文件中?
其实就是将一个长的字符串写入文件的问题,这个长的字符串中间有空格,比如:
23:45:45 开始 CCCC
[解决办法]
AnsiString data = "23:45:45 开始 CCCC ";
char *ptr = data.c_str();
fwrite(ptr, strlen(ptr), 1, fp);
[解决办法]
AnsiString str = "aaa " ;
fprintf( fp, "%s ", str.c_str() ) ;
[解决办法]
extern "C " __declspec(dllexport) int __stdcall cbf_Debug(const int iValues);
__declspec(dllexport) int __stdcall cbf_Debug(const int iValues)
{
int iLevel = 1;
AnsiString sFileName;
sFileName = ExtractFilePath(Application-> ExeName) + "sm301fev.txt ";
remove(sFileName.c_str());
FILE *fiLevel;
fiLevel = fopen(sFileName.c_str(), "a+ ");
fseek(fiLevel,0L,SEEK_END);//到文件尾
if(iValues == 0){
gbDebug = false;
iLevel = 1;
}
else{
gbDebug = true;
iLevel = 2;
}
AnsiString sValues = IntToStr(iLevel);
fwrite(sValues.c_str(),sValues.Length(),1,fiLevel);
fclose(fiLevel);
return 0;
}