create multiple class object.

Is it possible to create multiple class object from several input. For example:

class computer{};

class AI1: public computer{};

class AI2: public computer{};


int main()
{

string input[];

cin>>input[0];
cin>>input[1];
cin>>input[2];

for(int i = 0; i<3; i++)
{

if(input[i] == "AI1")
{
//create AI1 object
AI1 player1;
}

else if(input[i] == "AI2")
{
//create AI2 object
AI2 player1;
}
}

}

My question is:

1. is there any way to create the object for each input, so that the object name will be goes like this: player1, player2, player3....

2. is there any way to handle the input without having multiple "cin>>". For example if the user input is:

AI1 AI1 AI2 AI2

the input automatically stored in the array.


Thank in advance.
Last edited on
is there any way to create the object for each input, so that the object name will be goes like this: player1, player2, player3
You are looking for dynamic array or vector in this case.

is there any way to handle the input without having multiple "cin>>".
Loops. Loop until a certain sentiel value is found. Or read single string and extract input from it. You just need to determine what should signal the end of input before you start writing code.

And main question: what are you trying to do in your program? There might be a better approach.
A common obstacle when trying to help people solve their problems is that what people ask for and what they actually want are not always the same thing.
http://blogs.msdn.com/b/oldnewthing/archive/2006/03/23/558887.aspx
Topic archived. No new replies allowed.