Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing data from a loop to an array

Tags:

c++

loops

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;
}
like image 557
Shaquille Daley Avatar asked Aug 12 '26 01:08

Shaquille Daley


1 Answers

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.

like image 167
hekri Avatar answered Aug 14 '26 13:08

hekri