Xcode无法正确识别/读取文件

时间:2016-11-16 06:23:39

标签: c++ xcode fstream

我用c ++建立了一个程序来计算我在Don's暑期工作时欠我父亲的汽油金额。该程序所做的是从do while循环中的文件中读取两行,一行用于当天的起始里程,一行用于当天的结束里程。但是,我无法让程序正确读取文件。我很肯定我正确地打开它并把它放在正确的位置(与.cpp文件相同的文件夹)但它只是不能正确读取它。有什么想法吗?

#include <iomanip>
#include <iostream>
#include <fstream>

using namespace std;

int main()

{
ifstream inputFile;

inputFile.open("sample.txt");

int days; // number of days Alisha worked
int count = 1;
int totalMileage = 0;
int addMileage;
int startMileage;
int endMileage;
double avgMileage;
double moneyOwed;
double realOwed;
const double PER_MILE = 0.08125;

cout << endl;

cout << "How many days did Alisha work?" << endl;
cin >> days;

days++;

do
{
    inputFile >> startMileage;
    cout << "The starting mileage for day " << count << " is " << startMileage << endl;

    inputFile >> endMileage;
    cout << "The ending mileage for day " << count << " is " << endMileage << endl;

    addMileage = endMileage - startMileage;

    totalMileage = totalMileage + addMileage;

    count++;

    cout << endl;
}
while (count != days);

0 个答案:

没有答案