So I got a homework problem where I must use a .dat file and store the data into arrays (there's more to the homework, but this is just part of it). The first line of the data file contains the number of 3-dimensional points that define the model. We call these points the vertices of the model. For this model, the number is exactly 522. So this is an example of the data file,

522

-10900 -200 -19600

-10900 -100 -17800

-10900 -100 -20800

The next line of data contains the number of pen movements to draw the model. For this model, the number is exactly 891. Here is a little bit of that.

10900 400 -18700 (*this is from the 522*)

891 (*start of the new data*)

14 0

15 15

Note: The second number is a color to use when drawing a line to that vertex

I just really need an explanation of what to do and an example. I know that I must use the ifstream. But once I open the file, I have no idea how to store that data in the arrays.

//Constants const size_t M = 522; const size_t N = 891; const int S = 500; int main() { double data[M][3]; //this is the 522 data unsigned int vertex[N]; // int color[N]; size_t i, j; ifstream shuttle; shuttle.open("shuttle.dat"); if(shuttle.fail()) { cout << "Input file opening failed. \n"; exit(1); } //A function for the homework goes here, but I haven't written that because I want to figure out how to store the data first shuttle.close(); return END_SUCCESS; }

I believe that I must get the thing to read the first line and figure out how many lines of numbers it will use. Then store that into an array. Then once it reads 891, it will store the next 891 lines into another array. But I don't know how to put my words into code.

Thank you.