Answer the question
In order to leave comments, you need to log in
How to create an array from strings and fill it with values at random indices?
Goodnight.
How in C++ to create an array of strings (maximum 1000 values) and fill it with some values at random indexes? i.e. working indexes of all 1000 values can be 100 and 500, the remaining values can be null. Thank you!
Answer the question
In order to leave comments, you need to log in
#include <stdlib.h>
#include <string>
#include <ctime>
using namespace std;
// получаем рандомный индекс
int getIndex() {
srand((unsigned) time(0));
return ((rand() % 1000));
}
int main() {
string arr[1000] = { };
int index = getIndex();
arr[index] = "value";
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question