と割り当ては、下記のデータのファイル読み込みする:++ Cに複数行の文字列と整数を読み込み、入力ファイルとC++で表示するにはどうすればよいですか?
Turn on the Bright Lights
Interpol
9.49
House of Jealous Lovers
The Rapture
1.29
Fever to Tell
Yeah Yeah Yeahs
6.99
Desperate Youth, Blood Thirsty Babes
TV on the Radio
8.91
The Fragile
Nine Inch Nails
12.49
入力このデータを、その後、マトリックスとCDのの出力合計金額とどのように多くのCDのは、販売されたに表示されます。これまでのところ、最初の行は正しく表示されるだけで、残りの部分を表示するためには何を変更する必要があるのか分かりません。これまでに私が書いたものがここにあります。私は出力コードを開始していないと私はそれに問題がないように感じる。
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
using namespace std;
int main()
{
ifstream inputFile, processLine;
ofstream outputFile;
string title, band;
double price, total = 0;
inputFile.open("orders.txt");
while (!inputFile.eof())
{
getline(inputFile, title);
getline(inputFile, band);
inputFile >> price;
total += price;
cout << "Welcome to Megan McCracken's Online Music Store" << endl;
cout << "You have submitted the following order:" << endl;
cout << "***************************************************************************" << endl;
cout << "Title" << setw(46) << "Artist" << setw(24) << "Cost" << endl;
cout << title << setw(28) << band << setw(22) << fixed << setprecision(2) << price << endl;
cout << title << setw(30) << band<< setw(19) << fixed << setprecision(2) << price << endl;
cout << title << setw(20) << band << setw(20) << fixed << setprecision(2) << price << endl;
cout << title << setw(20) << band << setw(20) << fixed << setprecision(2) << price << endl;
cout << title << setw(20) << band << setw(20) << fixed << setprecision(2) << price << endl;
cout << "--------------------------------------------------------------------------" << endl;
cout << "Total Due:" << setw(75) << fixed << setprecision(2) << total << endl;
cout << "==========================================================================" << endl;
}
/* getline(inputFile, title);
cout << left << title;
getline(inputFile, band);
cout << setw(23) << band;
inputFile >> price;
cout << setw(10) << fixed << setprecision(2) << price << endl; */
system("pause");
return 0;
}
[ループ状態のeofが常に間違っている理由](http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong) – kfsone