i made a class, which stores it's parameter in a certain way..
i have a .txt file i need to read, and use those inputsparameter for my class. I've made an array of my class, but the problem is that the .txt look like this
5
5
2
3
35
5
65
62
32
..
So for every time i've read 3 element, i have to store them using my class..
so.. my first storing would be class man(5,5,2), and after that it would be class man(3,35,5) and so.. until the end..
I really don't have any idea on how i should do it..
i should have mentioned it's i a multidimensional array..
Which is where the problem is..
My idea was to increment each row and colloum.. but it would't work cause it increamentet to a higher value..
int i = 0
int j = 0
while(!file.eof())
{
file.seekg(0,ios::cur) >> value("here should the 3 parameters be ");
billy[i][j] = value;
if(j==height)
{j = 0;
i++;}
if(i==length)
cout << "done" << endl;
}
the 2d array, is made of the class i am using, so it would have no problems storing the values. the 2d array has length(int value) amount of collums and height(int value) amount of rows.
the problem with this code is, it continues endlessly, but I have to stop it when it has reached billy[length][height] which should be at the end of the file.
Well, I don't really follow your code (it doesn't compile, so it can't be the actual code). I'm not sure whether the issues are with the code itself, or the way in which it has been edited prior to posting.
But I'll try to make some comments.
Using while(!file.eof()) is generally not a good idea. Notice in my previous code I had while (fin >> a >> b >> c) which makes sense given that you want three values from the file to construct a single object of your class (I think).
I don't see the purpose of file.seekg(0,ios::cur), it is just repositioning the get pointer to where it is already ?
In your while loop I don't see j being incremented.
No...
I want to have a code which does what I mentioned in my prior post.
You are right about I want 3 values to construc a single object.
file.seek(0,ios::cur) is being used to reposition the pointer to where the datastream begin. I see that it should have been 0, but the datastream begins at line 3.
I and J is beeing incremented, so I can store the value at different positions in the 2d Array.
If the data begins at line 3, then I would add appropriate code to take care of that prior to the start of the loop. Probably changing the position within the loop is causing the loop to never terminate.