我想制作一个程序,用户输入几个名字,然后随机选择一个名字。但是,我不知道如何得到要挑选的字符串。我想将每个字符串分配给一个 int,然后当一个 int 被选择时,字符串也是如此。请帮我。
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
using namespace std;
void randName()
{
string name;//the name of the entered person
cout << "write the names of the people you want.";
cout << " When you are done, write done." << endl;
int hold = 0;//holds the value of the number of people that were entered
while(name!="done")
{
cin >> name;
hold ++;
}
srand(time(0));
rand()&hold;//calculates a random number
}
int main()
{
void randName();
system("PAUSE");
}