I am trying to build a 2 dimensional array in C++ while I don’t know how many rows I will have. Here is some code:
In the header file:
class model
{
... ...
float vertices[][3];
... ...
}
And in the .cpp file:
istringstream iss(str);
for (int i = 0; i <=2; i++)
{
iss >> vertices[counter][i];
}
Is this a proper way to handle it? I got a segmentation fault, I just want to make sure it’s not caused by the way I use arrays. Also is there a better way to handle this, thanks.
You need to either use pointers, or use a dynamically resizable container such as
std::vectorwhen you don’t know the size.