我需要幫助。我正在編寫這個程序,需要計算.csv文件中兩個整數之間的差異。找出差異是很容易的,但是當我列出差異列表時,它們沒有特定的順序。我想挑選出具有最高價值的差異和特別的結果。我會怎麼做呢?Cout按降序排列C++
double diff;
int astate;
string line8;
ifstream myfile8 ("elect12.csv");
//cout << endl << "Total Popular Votes for Other Candidates: ";
while (getline (myfile8, line))
{
istringstream iss(line);
int a, b, c, d, e;
if (!(iss >> a >> b >> c >> d >> e)) //{ break; }
diff = (a-b);
diff = diff/d;
diff = diff*100;
astate = diff;
/*cout << "Obama's best state was " << line8 << ", where he won by " << diff << " points." << endl;*/
cout << astate << endl;
將差值換算成百分比。現在,& b之間的所有差異正在返回。我如何才能返回最大的差異?
對不起,如果這沒有意義。
cout內循環是有罪的 –
你必須保存最大的差異yoursef –
並在外側的循環,顯示它 –