//=========================================================================== // Revised 26 January 2010 FILE SAVE AND OPEN //=========================================================================== // PLACE THE FOLLOWING TWO DIALOG COMPONENTS ON YOUR DESIGN WINDOW: // TSaveDialog and TOpenDialog // IT DOESN'T MATTER WHERE YOU PUT THEM. THEY WILL NOT BE SEEN. // PUT THIS WITH THE INCLUDES AT THE TOP: #include // YOU NEED TO TYPE THIS IN // FUNCTIONS: //---------------------------------------------------------------- SAVE STUFF void saveStuff (void) { if (Form1->SaveDialog1->Execute()) { ofstream outfile(Form1->SaveDialog1->FileName.c_str()); // assuming you're saving two arrays (cityX[] and cityY[]) of size "size": outfile << size << endl; for (int i = 0; i < size; i++) { // use " " and/or endl as record separators: outfile << cityX[i] << " " << cityY[i] << endl; } outfile.close(); } } //---------------------------------------------------------------- OPEN STUFF void openStuff (void) { if (Form1->OpenDialog1->Execute()) { ifstream infile(Form1->OpenDialog1->FileName.c_str()); // assuming you are reading in values for two arrays as above. infile >> size; for (int i = 0; i < size; i++) { infile >> cityX[i]; infile >> cityY[i]; } infile.close(); } } // FUNCTION CALLS IN BUTTON EVENT HANDLERS: //--------------------------------------------------------- SAVE STUFF BUTTON void __fastcall TForm1::ButtonSaveClick(TObject *Sender) { saveStuff(); } //--------------------------------------------------------- OPEN STUFF BUTTON void __fastcall TForm1::ButtonOpenClick(TObject *Sender) { openStuff(); }