Access to structure vectors

I have a structure:

struct OutputStore 
{
    int myINT;
    string mySTRING;
}

If I create an array of type OutputStore as follows:

OutputStore *OutputFileData = new OutputStore[100];

then I can access it with

OutputFileData[5].myINT = 27;

But if I use a vector instead of an array:

vector<OutputStore> *OutputFileData = new vector<OutputStore>(100);

Then I get "... is not a member of the std :: vector <_Ty>" error if I try:

OutputFileData[5].myINT = 27;

Since you can access the vector through it, just like you can array why this line does not work. I am just curious to know, as this suggests that I lack a fundamental understanding.

(I changed to a vector as I wanted push_back, because I don’t know the size that my data will reach. I have it working using the constructor to structure and pushing back through it ... I just want to understand what is going on here)

+3
2

.

vector<OutputStore> OutputFileData(100);

. ,

(*OutputFileData)[5].myINT = 27;
+9

, [] , , . , .

(*OutputFileData)[5].myINT = 27;
//*OutputFileData is the same as OutputFileData[0]

[] , .

vector<OutputStore> OutputFileData(100);
OutputFileData[5].myINT = 27;

- , ++. , , .

+3

Source: https://habr.com/ru/post/1713244/


All Articles