Home > Back-end >  The contents of a different file input to a class object in the array
The contents of a different file input to a class object in the array

Time:09-23

Excuse me everybody a great god, and there how to solve such a problem,
Write a class, have more than one member variable;
Class A
{
Double the ex, ey, ez
Double hx, hy, hz;
}
A. an array of objects G [50] [100].
Have a folder under the ex, ey, ez, hx, hy, hz TXT file of each file is 50 * 100 matrix,
For example the ex. TXT file, there is 1.. . 99, 100,
.... .
.... .
50... 99, 100,
Now thinking of the ex, ey, ez, hx, hy, import the contents of hz to G,
Such as thinking of the ex imported into in> G [50] [100]. Ex, ey import to G [50] [100]. Ey;
Is variable is a little bit more, a member variable name is not the same, how can cycle, the import of data in different file into an array of objects of different member variable

CodePudding user response:

 ifstream ifex (ex. TXT "); 
Ifstream ifey (" ey. TXT ");
Ifstream ifez (" ez. TXT ");
String linex liney, linez;
for(int i=0; i<50; I++)
{
Getline (ifex, linex);
Getline (ifey, liney);
Getline (ifez linez);
Istringstream isex (linex);
Istringstream isey (liney);
Istringstream isez (linez);
for(int j=0; j<100; J++)
{
Isex> G [I] [j]. Journal of ex;
Isey> G [I] [j]. Journal of ey;
Isez> G [I] [j]. Ez;
}
}
No error judgment (such as file accident end, etc.), join,
  • Related