Hello, friends! I have this question: there is a class in it, I defined a vector with type string. And I call this class with this array and I want to transfer the name of the file there, but it displays an error stating that the array has gone out of the border (vector substript out of range). How can this be avoided? Thank you in advance. Here is the class:
class resqmobject { public: string title; string uid; string description; vector <float> floatdata; vector <int> intdata; vector <SplitReferenses> SRData; vector <FaultStruct> FData; vector <coord> CoordData; vector <float> ZCORN; vector <string> FileName; }; And this is how I want to add the file name to the vector:
for (int i = 0; cursor < arr.size(); i++){ string strFileName = ofn.F_Pillars; ofstream fout(ofn.F_Pillars); char *c = new char[strFileName.length() + 1]; FPObject.FileName[i].push_back(*c); }
FPObject.FileNameis a vector of lines,FPObject.FileName[i]is the i-th line in it,FPObject.FileName[i].push_back(*c);- an attempt to add the first character from the (uninitialized) arraycto the i-th line of your vector. It may add (although what do you get?), But you, judging by the error message, have many more elements inarrthan inFileName. - Harry