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

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 &lt;&lt; user_name &lt;&lt; endl; // Write the name to the file. outfile &lt;&lt; age &lt;&lt; endl; // Write the age to the file. outfile.close(); // Close the output file. } else // If error occurred, display message. { cout &lt;&lt; &quot;An error occurred while opening the file.\n&quot;; } return 0; }...
View Full Document

This note was uploaded on 06/20/2011 for the course COMPUTING 379 taught by Professor Dr.anoopsarkar during the Spring '11 term at American College of Computer & Information Sciences.

Ask a homework question - tutors are online