Dynamicly sized arrays

Hey, I'm messing around with making a cards against humanity clone for educational purposes but I'm running into a a little problem

I'm making the hardest bit first (the white cards) but I've hit a snag.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int main ()
{
    ifstream cardlist;
    cardlist.open ("wcards.txt");
    int cardnumber = 0;
    string cardtext;
    string cardarray [cardnumber];
    while (cardlist.good())
    {
        getline(cardlist,cardtext);
        cardarray[cardnumber] = cardtext;
        cardnumber++;
    }
    cout << cardarray[5];
    return 0;
}


it compiles and then it breaks
Process terminated with status -1073741510 (0 minutes, 9 seconds)


I think it's the way I've tried to keep expanding the array but I'm not sure. Any insight you could give would be useful, thanks.
The size of the array is decided by the value of cardnumber on line 7. cardnumber is 0 so the size of the array will be zero and it's not possible to later change the size. You should consider using a container like std::vector that can change size.
http://www.cplusplus.com/reference/vector/vector/
Thanks
Last edited on
Topic archived. No new replies allowed.