123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
// NameGame.cpp : Defines the entry point for the console application. // Program to spell out my name in the order of lastname, firstname. // Joshua Wortman // 3/14/17 #include "stdafx.h" #include <iostream> #include <iomanip> #include <string> #include <fstream> using namespace std; void Pause() { string junk; cout << "Press Enter to continue..."; cin >> junk; } int main() { // declare file variables ifstream Infile; ofstream Outfile; ofstream Logfile; // declare variables string myname; int lastname, firstname; char junk; // open files Logfile.open("f:\\myname.log"); if (Logfile) { cout << "Log file created.\n\n"; } else { cout << "FAILED to open myname.log\n\n"; Pause(); } Infile.open("f:\\lastname.dat"); if (Infile) { Logfile << "lastname.dat opened successfully.\n\n"; } else { Logfile << "FAILED to open lastname.dat\n\n"; } Infile.open("f:\\firstname.dat"); if (Infile) { Logfile << "firstname.dat opened successfully.\n\n"; } else { Logfile << "FAILED to open firstname.dat\n\n"; } Outfile.open("f:\\myname.dat"); if (Outfile) { Logfile << "myname.dat opened successfully.\n\n"; } else { Logfile << "FAILED to open myname.dat\n\n"; } // get input // cout << "What is your last name? "; // cin >> firstname; getline(Infile, myname); if (Infile) { Logfile << "last name was read successfully= " << myname << "\n\n"; } else { Logfile << "FAILED to read last name\n\n"; } // cout << "What is your first name? "; // cin >> lastname; getline(Infile, myname); if (Infile) { Logfile << "first name was read successfully= " << myname << "\n\n"; } else { Logfile << "FAILED to read first name\n\n"; } // display results cout << endl << "Your name is " << lastname << ", " << firstname << endl << endl; Outfile << endl << "Your name is " << lastname << ", " << firstname << endl << endl; // close files Infile.close(); Outfile.close(); Logfile << "Program ended.\n"; Logfile.close(); // freeze screen Pause(); return (0); }
int lastname, firstname;