I'm new to c++ and my question is how do I store data from a loop cycle into a array, then print it? Do I need to make another loop? if so how do I go about that? also if what I ask is possible, when every time I re-run the compiler will the array above get re-written or erased(hope it does)?
int getcard()
{
srand((unsigned)time(0));
int x;
string mix[10];
string h;
do
{
for (int index = 0; index < 10; index++)
{
x = rand() % 18;
h = master[x];
cout << h << endl;
}
mix[10] = h;
}
while (false);
return 0;
}
This piece of code creates a string array initializes it's elements to "string" and prints it out.
string array[10];
for (int i=0; i<10; i++){
array[i] = "string";
}
for (int i=0; i<10; i++){
cout<<array[i] <<" ";
}
You should try something in the line of this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With