Home > Back-end >  The FILE * fp=fopen (OpenDialog1 -> FileName. The c_str (), "rb"); XE8 file read always
The FILE * fp=fopen (OpenDialog1 -> FileName. The c_str (), "rb"); XE8 file read always

Time:09-29

The FILE * fp=fopen (OpenDialog1 - & gt; FileName. C_str (), "rb"); XE8 file read always prompt error, how to change

CodePudding user response:

What error message?

CodePudding user response:

AnsiString STR=OpenDialog1 - & gt; The FileName.
The FILE * fp=fopen (STR) c_str (), "rb");

CodePudding user response:

First, using the FILE in XE series, libraries need to quote the stdio. H

# include & lt; Stdio. H>//reference stdio. H library

Second, in a series of XE has wide characters used by default, it is recommended to use the wide character function of form a complete set _wfopen to read and write files

# include & lt; Stdio. H>//reference stdio. H library

Void __fastcall TForm1: : Button1Click (TObject * Sender)
{
The FILE * outf;//define a file pointer
If (OpenDialog1 - & gt; The Execute ())
{
Outf=_wfopen (OpenDialog1 - & gt; FileName. W_str (), L "rb");
}
}


CodePudding user response:

The
reference 3 floor KFRGHT response:
first, using the FILE in XE series, libraries need to quote the stdio. H

# include & lt; Stdio. H>//reference stdio. H library

Second, in a series of XE has wide characters used by default, it is recommended to use the wide character function of form a complete set _wfopen to read and write files

# include & lt; Stdio. H>//reference stdio. H library

Void __fastcall TForm1: : Button1Click (TObject * Sender)
{
The FILE * outf;//define a file pointer
If (OpenDialog1 - & gt; The Execute ())
{
Outf=_wfopen (OpenDialog1 - & gt; FileName. W_str (), L "rb");
}
}

Positive solution

CodePudding user response:

reference 5 floor xiao_la_mu reply:
KFRGHT big reply to more perfect just the way they are!


 
Void __fastcall TForm1: : Button1Click (TObject * Sender)
{
if(! OpenDialog1 - & gt; The Execute ())
{
return;
}
The FILE * outf;//define a file pointer
Outf=_wfopen (OpenDialog1 - & gt; FileName. W_str (), L "rb");
}


 perfect
  • Related