Program crashes after populating array

I am trying to make a simple game with multiple players, but the number of players is determined by the user. The number is passed into an array where the names of the players are stored, however my program crashes after i finish entering the player's names. Can anyone help me figure what I am doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<iostream>
#include<string>

using namespace std;

int main()
{
	int numPlayers;

	cout << "How many players are there? >> ";
	cin >> numPlayers;

	string *name = new string[numPlayers]; //Create array with length of numPlayers

	for (int x = 1; x <= numPlayers; ++x) //Populate the array
	{
		cout << "Enter player " << x << "'s name >> ";
		cin >> name[x];
	}
	cout << endl;

        return 0;
}
Array indices start from 0.
Last edited on
Thank you, I can't believe I overlooked that.
Topic archived. No new replies allowed.