I've been trying to figure out why cout won't print if in a while loop. I already know that the file is being read, and cout works outside of the loop. I need help with this ASAP.
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
int main()
{
ifstream inData("inData.txt");
if (inData.fail())
{
cerr << "Error: File Not Found" << endl;
}
int l;
int w;
int r;
string nameFirst;
string nameLast;
int age;
double savings;
while (inData >> l >> w >> r >> nameFirst >> nameLast >> age >> savings)
{
cout << l << endl;
}
system("pause");
}
Likely, it wont print because the contents of the file 'indata.txt' does not match the format implied in expression inData >> l >> w >> r >> nameFirst >> nameLast >> age >> savings
As I understand it, each term (separated by a space) will be assigned a variable in the order that I have them in the while function. I'm guessing that I need something more?