1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#include <iostream>
#include <fstream>
#include <cstdlib> // needed for exit()
#include <string>
#include <iomanip> // needed for formatting
using namespace std;
int main()
{
const int noofemployees = 5;
string filename = "employee.dat"; // put the filename up front
string filename1 = "employee.dak";
string names[noofemployees] = { "Andrew", "Burrows", "Fain", "Janney", "Smith" };
char group[noofemployees] = { 'A', 'W', 'B', 'P', 'G' };
int code[noofemployees] = { 10031, 10067, 10083, 10095, 10005 };
double code1[noofemployees] = { 7.82, 9.14, 8.79, 10.57, 8.50 };
string dob[noofemployees] = { "12/18/2008", "06/9/2006", "05/18/2007", "09/28/2008", "12/20/2007" };
string namescopy[noofemployees], dobcopy[noofemployees];
string groupcopy[noofemployees];
string code1copy[noofemployees];
string codecopy[noofemployees];
ofstream employeedata;
// need ifstream to read the information
ifstream employeeread;
ofstream employeecopy;
employeedata.open("employee.dat");
employeecopy.open("employee.dak");
for (int i = 0; i < noofemployees; i++)
{
cout << names[i] << setw(10) << group[i] << setw(10) << code[i] << setw(10) << code1[i] << setw(10) << dob[i] << setw(10) << endl;
employeedata << names[i] << setw(10) << group[i] << setw(10) << code[i] << setw(10) << code1[i] << setw(10) << dob[i] << setw(10) << "\n";
}
employeedata.close();
employeeread.open("employee.dat");
if (employeeread.fail())
{
cerr << " Your file has failed to opened" << endl;
}
int counter = 0;
while (!employeeread.eof())
{
string readbuffer;
std::getline(employeeread, readbuffer);
// output to new file the data you read.
employeecopy << readbuffer << "\n";
counter++;
}
employeecopy.close();
cout << counter << "items found ";
int x;
cin >> x;
return 0;
}
|