{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

fileapp - Open file for output if(outfile If no error...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// fileapp.cpp / #include <iostream.h> #include <fstream.h> // necessary for file I/O #include "apstring.h" // necessary for string object # int main() { apstring user_name; int age; ofstream outfile; // Declare file stream named outfile. cout << "Enter your name: "; // Get name from user. getline(cin, user_name); cout << "Enter your age: "; // Get age from user. cin >> age; outfile.open("NAME_AGE.DAT",ios::out);
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // Open file for output. if (outfile) // If no error occurs while opening file { // write the data to the file. outfile << user_name << endl; // Write the name to the file. outfile << age << endl; // Write the age to the file. outfile.close(); // Close the output file. } else // If error occurred, display message. { cout << "An error occurred while opening the file.\n"; } return 0; }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online