How to convert AnsiString to Char in C ++ Builder?

2

I need to choose a txt file through OpenDialog , to open through fopen . The problem I'm encountering and the conversion. The fopen function has as parameter const char , since opendialog returns the file path as a ansistring (follow the code)

void __fastcall TForm1::Button2Click(TObject *Sender)
{
 AnsiString Arquivo;

 FILE *Fin;

 if(OpenDialog1->Execute())
   Arquivo = OpenDialog1->FileName;
 Fin = fopen(Arquivo,"rt") ;
 Button1->Enabled = true;
}
//-----
    
asked by anonymous 21.07.2016 / 21:13

1 answer

2

The c_str() method converts the text to const char * . So just use Arquivo.c_str() .

    
21.07.2016 / 21:17