C++ 尝试使用while循环将数据从文件读入数组。还必须检查以确保第一个也是唯一的值不是-1

C++ 尝试使用while循环将数据从文件读入数组。还必须检查以确保第一个也是唯一的值不是-1,c++,arrays,C++,Arrays,我打算让它显示从文件中读取的值,但它在我输入文件路径后才结束 输入文件包含: 5658845408 4520125 25.25 9.25 7895122 30 10.50 87775411012 8451277 50 10.20 1302850 35.20 7.50 -一, 它应该是如果checkRead=-1,而不是如果checkRead=-1,如果checkRead=-1在您的情况下总是正确的 checkRead = read(empId, hours, payRate); if (chec

我打算让它显示从文件中读取的值,但它在我输入文件路径后才结束

输入文件包含:

5658845408

4520125 25.25 9.25

7895122 30 10.50

87775411012

8451277 50 10.20

1302850 35.20 7.50

-一,

它应该是如果checkRead=-1,而不是如果checkRead=-1,如果checkRead=-1在您的情况下总是正确的

checkRead = read(empId, hours, payRate);
if (checkRead = -1) // should be if (checkRead == -1)
    return 0;

for (int c = 0; c < SIZE; c++)
    cout << empId[c] << " " << hours[c] << " " << payRate[c] << endl;
如果count=0&&tempId<0,则应为如果count==0&&tempId<0:


非常感谢!我完全忘记了==并且它将0返回到main,从而结束了程序。我现在让它工作了,它在最后显示了一堆疯狂的数字,但我相信我会弄明白的。再次感谢你的帮助。
checkRead = read(empId, hours, payRate);
if (checkRead = -1) // should be if (checkRead == -1)
    return 0;

for (int c = 0; c < SIZE; c++)
    cout << empId[c] << " " << hours[c] << " " << payRate[c] << endl;
while (tempId >= 0 && count < SIZE)
{
    infile >> id[count] >> hrs[count] >> rate[count];
    tempId = id[count];
    if (count = 0 && tempId < 0) // should be if (count == 0 && tempId < 0)
    {
        cout << "Error. This file contains no data" << endl;
        return -1;
    }
    count++;
}