There is a structure

struct Informer { char item[20]; char Platform[20]; char TimeBack[20]; }; 

And filling it out of the file

 ifstream in; Informer mas[20]; in.open("1.txt"); int i = 1; int n = 0; while (!in.eof()) { n++; if (n != 4) switch (n) { case 1: in >> mas[i].item; break; case 2: in >> mas[i].Platform; break; case 3: in >> mas[i].TimeBack; } else { n = 0; i++; } } 

How to stuff it into a function?

    1 answer 1

    Just stuff it into a function. Passing a pointer to the structure as a parameter (that is, the first element of the array of structures is to make mas the parameter of this function), and the function will fill the array with data from the file. It is also desirable to pass through the parameter the maximum number of readable elements (the size of this array, so as not to go beyond its limits). The third parameter can be the file name (open inside the function) or an already open stream (open in advance before the function is called). And you can return a sign of success / error or the number of actually read items (then 0 will automatically correspond to open / read errors, etc.).