You need to dynamically allocate an array of BLOCK blocks and dynamically create each block and feed it into an array with identifier / fields (purpose and nature are -int, string, other - identifiers are not specified in your question)
As pointed out in the comments, numblocks is unknown at compile time and therefore tied to a crash (the amount of memory on the stack is also limited, even if the compiler decides to give you an exception and perform the distribution behind the scenes after the value is known at run time)
int numblocks; std::cin >> numblocks; BLOCKS *blarray = new BLOCKS[numblocks]; for(int i=0; i < numblocks; i++) { BLOCK *b = new BLOCK() std::string identifier; std::cin >> identifier; std::cin >> b->x1 >> b->y1 >> b->x2 >> b->y2; blarray[i] = b; }
Of course, you need to control the deallocation of the memory later with deletion and deletion []
Note. How can you not use std :: vector if you can use the namespace std ... ??? (this refers to the original question, which was edited to reflect the vector, you cannot use and remove the link to the possibility of using "namespace std")
source share