I am having difficulty getting input from a file because I can't figure out how to create a function inside a class that will transfer the data to the class variables. I cannot find an example to work from anywhere. Is there a standard formula for this?
Reading from a file is very similar to reading from cin. Instead of
cin >> x >> y >> z
it becomes
infile >> x >> y >> z
Is there a standard formula for this?
It will depend on the format of the file - sometimes there are commas, or names which contain spaces etc, it depends on the data. One thing that might be considered common, if not 'standard', is to place the input statements inside the condition of a while loop
1 2 3 4
while (infile >> x >> y >> z)
{
// do something with x, y and z
}
Wow, no I mean wow! Thank you both so much! Now it makes sense to me. I just needed a little explanation and a great example, and that is exactly what I got you guys a re the best.