// Mr. Minich
// CMPSC 201
// Ch. 8 Demo Program #5
// January 20, 2000
// Purpose - to illustrate how to open a file for output and how to write to that file.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string name; // player's name
int score = 0; // player's score
ofstream hiScores; // filepointer to file being written to
// notice the 'o' in "ofstream" which indicates output
hiScores.open("HiScores.txt"); // opening the file for output
while (1) // infinite loop until break is executed below
{
cout << "Enter your name (type \"xxx\" to quit): ";
cin >> name;
if (name == "xxx") // exiting loop when sentinel xxx is inputted
{
break;
}
cout << "Enter your score: ";
cin >> score;
// writing names and scores to separate lines
hiScores << name;
hiScores << endl;
hiScores << score;
hiScores << endl;
}
return 0;
}// end of main