I need to make a dynamic array in C++, and ask a user to input a name until the user types exit
.
It should keep asking for more and more names, recording them to a dynamic string array, then randomly choosing as many names as the user wants from the list.
I should be able to figure out the random numbers part, but the continuous input is giving me issues. I'm not sure how to have the length variable continue changing values.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int length;
string* x;
x = new string[length];
string newName;
for (int i = 0; i < length; i++)
{
cout << "Enter name: (or type exit to continue) " << flush;
cin >> newName;
while (newName != "exit")
{
newName = x[i];
}
}
cout << x[1] << x[2];
int qq;
cin >> qq;
return 0;
}
Any help would be greatly appreciated.