It fails on MSVC++ 6.0 for me, but works on Dev-C++. Technically, I believe the C++ standard forbids declaring arrays like you did, but the latest C standard allows it. It is possible that Dev-C++ allows it because of that. I wouldn't recommend using it though, because for now at least, it is non-standard in C++. You might want to consider learning an alternative that compiles on all C++ compilers.
Using vectors and strings (my recommended solution):
Code:
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
int player;
cout<<"number of players: ";
cin>>player;
cin.ignore();
vector<string> name(player);
for (int x=1; x<=player;x++)
{
cout<<"player "<<x<<" enter your name please\n";
getline(cin, name[x-1]);
}
//this part is just to test
for (int i=0; i<player;i++)
{
cout<<name[i]<<"\n";
}
cin.get();
}
Or using new and delete:
Code:
// ??? I'm tired and going to bed, maybe somebody else can give
// you an example using C style strings and new and delete. ;)