#include<iostream>
#include<string>
#include<fstream>
#include<vector>
using namespace std;
void check(ifstream &iFile)
{
if (!iFile.is_open())
{
cout << "Data file not found!" << endl;
system("pause");
exit(1); // exit the program if the file is not found.
}
}
void readIn(ifstream &iFile, vector<string> &fName, vector<string> &lName, vector<string> &jTitle, vector<string> &eID, vector<double> &hoursWorked, vector<double> &wage, vector<int> &deductions, vector<double> &sPay, string sTemp, double dTemp, int iTemp)
{
while (!iFile.eof())
{
iFile >> sTemp;
fName.push_back(sTemp);
iFile >> sTemp;
lName.push_back(sTemp);
iFile.ignore();
getline(iFile, sTemp);
jTitle.push_back(sTemp);
iFile >> sTemp;
eID.push_back(sTemp);
iFile >> dTemp;
hoursWorked.push_back(dTemp);
iFile >> dTemp;
wage.push_back(dTemp);
iFile >> iTemp;
deductions.push_back(iTemp);
iFile >> dTemp;
sPay.push_back(dTemp);
}
cout << "completed" << endl;
}
int main()
{
ifstream iFile;
iFile.open("data.txt");
check(iFile);
vector<string> fName, lName, eID, eStatus, jTitle;
vector<double> nPay, gPay, oPay, oHours;
vector<double> hoursWorked, wage, sPay;
vector<int> deductions;
// temporary names to pass to the vector
string sTemp; // string temp
double dTemp=0; // double temp
int iTemp=0; // integar temp
readIn(iFile, fName, lName, jTitle, eID, hoursWorked, wage, deductions, sPay, sTemp, dTemp, iTemp);
/* while (!iFile.eof())
{
iFile >> sTemp;
fName.push_back(sTemp);
iFile >> sTemp;
lName.push_back(sTemp);
iFile.ignore();
getline(iFile, sTemp);
jTitle.push_back(sTemp);
iFile >> sTemp;
eID.push_back(sTemp);
iFile >> dTemp;
hoursWorked.push_back(dTemp);
iFile >> dTemp;
wage.push_back(dTemp);
iFile >> iTemp;
deductions.push_back(iTemp);
iFile >> dTemp;
sPay.push_back(dTemp);
}*/
int sizeOf = fName.size();
for (int a = 0; a < sizeOf; a++)
{
cout << fName.size() << " FName " << fName[a] << " LName " << lName[a] << " JobTitle " << jTitle[a] << endl;
cout << "EmployeeID " << eID[a] << " Hours Worked " << hoursWorked[a] << " Hourly Wage " << wage[a] << endl;
cout << "Deductions " << deductions[a] << " Salary Pay " << sPay[a] << endl;
}
system("pause");
return 0;
}
私の機能は何もしません。それはコンパイルされますが、出力はありません。事は、それが完全にうまく動作するすべての部分からベクトルsPayを取り出すときです。その部分がなぜ機能していないのかについての示唆はありますか?私の限られた知識から、それは完全にうまくいくはずですが、私はこれを引き起こす原因を理解できません。ベクトル関数プログラムの問題
私の例のテキストファイルには、あなたの入力ファイルはあなたの読書コードが一致しません
Alan
WakeField
IT GUY
T2034
40
15
1
Hourly
0.00
[なぜループ状態のiostream :: eofが間違っていると思われますか?](https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered -wrong) –
私はあなたに[良い初心者の本を拾う]ことをお勧めします。(http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) *および*クラス*を使用して密接に関連するデータをグループ化します。もちろん、ローカル変数についても! –
自分自身に質問してください: 'sPay'を読んでもプログラムが動作しない場合は、入力に何か問題があるはずです。その前に何を読んでいますか、入力ファイルの次のデータは何ですか? – 1201ProgramAlarm