我在这里遇到一个奇怪的问题。我有一个名为input.txt的文件,我想读取该文件中的行,并将其写入名为useroutput.txt的文件中。我可以使用Visual C ++在Windows中完成。我目前正在使用eclipse,因为Visual C ++不能在mac上运行。 out文件已成功创建,但没有读取行或正在写入文件。我对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;
}