COM1100 -- Winter2000 -- Yuhong Yin
5
Example 2 – ofstream&
nWrite a function GetOutputFile that will receive one output file stream as argument, and will open the file stream by asking the user to enter a file name.
nvoid GetOutputFile(ofstream& OutFile){
       string OutFileName;
       RequestString("Enter output file name: ", OutFileName); // Get file name
 
       OutFile.open(OutFileName.c_str());        // If a name was entered, try to open the file
        if (!OutFile){                                      // test if the open operation is successful
cout << "Cannot open " << OutFileName << endl;
exit(1);
      }
}