这是我到目前为止的代码。我正在从输入文件中获取数据。该文件包含我调用的每个变量所需的所有数据,但是当我运行它时,我只得到一次迭代,然后退出循环。我需要它运行直到它到达文件的末尾。
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
using namespace std;
int main ()
{
ifstream pTemp("PlanetCelsius.dat");
int pNumber, pSize;
string pName;
double cTemp, fTemp;
cout << "Number\t" << "Planet Name\t" << "Diameter\t" << "Celsius\t" << "Fahrenheit" << endl;
while (pTemp >> pNumber)
{
while (pTemp >> pName)
{
while (pTemp >> pSize)
{
while (pTemp >> cTemp)
{
pTemp >> pNumber;
cout << pNumber << " ";
}
pTemp >> pName;
cout << pName << " ";
}
pTemp >> pSize;
cout << pSize << " ";
}
pTemp >> cTemp;
fTemp = 9 * (cTemp) / 5 + 32;
cout << cTemp << " " << fTemp << endl;
}
system ("PAUSE");
return 0;
}