// This program writes data to a file. // Shows error checking. #include #include using namespace std; int main() { ofstream outfile; // instantiate file pointer object outfile.open("public_radio.txt"); // associate file with file pointer object if (!outfile) { cout << "Error opening file." << endl; return 1; // exit program with an error code } cout << "Writing to the file ... "; outfile << "KCMP\t" << 89.3 << endl; outfile << "KNOW\t" << 91.1 << endl; outfile << "KSJN\t" << 99.5 << endl; outfile.close(); // close the file! cout << "Done!" << endl; return 0; }