我在这里遇到了一个奇怪的问题。我有一个名为 input.txt 的文件,我想读取该文件中的行并将其写入名为 useroutput.txt 的文件中。我可以使用 Visual C++ 在 Windows 中做到这一点。我目前正在使用 eclipse,因为 Visual C++ 无法在 mac 上运行。输出文件已成功创建,但没有读取行或正在写入文件。我对 C++ 有点陌生。有人可以帮忙吗?提前致谢。
以下是我的代码
#include <iostream>
# include <fstream>
#include <iomanip>
using namespace std;
int main()
{
double saleAmount =0;
double ticketPrice;
int ticketsSold;
int totalTicketsSold = 0;
ifstream inFile;
ofstream outFile;
inFile.open("inputstadium.txt");
outFile.open("UserOutput.txt");
outFile<<fixed<<showpoint<<setprecision(2);
cout << "Processing data" << endl;
//1st row
inFile >> ticketPrice >> ticketsSold;
saleAmount = saleAmount + ticketPrice*ticketsSold;
totalTicketsSold = totalTicketsSold + ticketsSold;
//2nd row
inFile >> ticketPrice >> ticketsSold;
saleAmount = saleAmount + ticketPrice*ticketsSold;
totalTicketsSold = totalTicketsSold + ticketsSold;
//3rd row
inFile >> ticketPrice >> ticketsSold;
saleAmount = saleAmount + ticketPrice*ticketsSold;
totalTicketsSold = totalTicketsSold + ticketsSold;
//4th row
inFile >> ticketPrice >> ticketsSold;
saleAmount = saleAmount + ticketPrice*ticketsSold;
totalTicketsSold = totalTicketsSold + ticketsSold;
outFile << "Number of Tickets sold = " << totalTicketsSold<<endl;
outFile << "saleAmount = $ " << saleAmount<< endl;
inFile.close();
outFile.close();
return 0;
}