Solution:
First of all, you need to read the documentation thoroughly instead of roughly before started coding in any programming language. I can see in your code you declared an array myArray as we do in java. There is a little bit difference between java a c++ declaring an array.
When we declare an array in java we do not allocate any memory in it. What it is doing is creating a pointer to the memory taken when the array is then initialized.
On the other hand, when an array is declared in C++, the memory is allocated at the time of declaration, so declaring an empty array is a big no-no because the compiler doesn’t know how much memory to reserve for the array.
This is the key difference between java and c++ in this case.
Keep discovering. Thanks