このプログラムは、コンピューター上の場所からファイルを取得し、従業員のSSNの最後の4桁のみを表示する画面に印刷します。
#include <iostream>
#include <fstream>
#include <cstdlib> // needed for exit()
#include <string>
using namespace std;
int main()
{
double Thanks_for_your_time;
string filename = "C:\\Emp\\employee_info.txt";
string line;
ifstream inFile;
inFile.open("C:\\Emp\\employee_info.txt"); // open the file with the
// external name
if (inFile.fail()) // check for a successful open
{
cout << "\nThe file was not successfully opened"
<< "\n Please check that the file currently exists."
<< endl;
exit(1);
}
cout << "\nThe file has been successfully opened for reading\n"
<< endl;
while (getline(inFile,line))
cout << line << endl;
// statements to read data from the file would be placed here
do
{
cout << "\nThanks for your time(0 to quit):";
cin >> Thanks_for_your_time;
}
/*
ファイルは読み取り用に正常に開かれました
従業員名:Harry Heck従業員SSN:987-98-7987(最後の4つを除くすべてが「x」または空白である必要があります)従業員の時給:$ 20.15今週の労働時間:40.25総賃金:$ 811.04
従業員名:Sally Smothers従業員SSN:654-65-4654(最後の4つを除くすべてが「x」または空白である必要があります)従業員の時給:$ 50.25今週の労働時間:40.35総賃金:$ 2027.59
お時間をいただきありがとうございます(終了する0):* /