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

Asked

Viewed 400 times

3

I need to pick a file txt through the OpenDialog, to open through fopen. The problem I’m found is in the conversion. The function fopen has as a parameter a const char, already opendialog returns the file path as a ansistring (follows 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;
}
//-----

1 answer

2


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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.