63 839
Assignments Done
99,2%
Successfully Done
In August 2018

Answer to Question #71071 in C++ for MARK ANDREWS

Question #71071
Hi
How do I read a list of names from a file- into an array of strings. Once I have the array - h ow do I use a random number generator to shuffle the order and pick 2 students at a time?
Expert's answer
As variant it can be done as follows
std::string name;
std::vector<std::string> stringArray;
std::ifstream fin("somefile.txt", std::ios::read);

std::getline (fin,name);
stringArray.push_back(name);

size_t s1 = rand() % stringArray.size();
size_t s2 = rand() % stringArray.size();

std::cout<< stringArray[s1] << std::endl;
std::cout << stringArray[s2] << std::endl;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
15.11.17, 22:06

Dear MARK ANDREWS,

You're welcome. We are glad to be helpful.
If you liked our service please press like-button beside answer field. Thank you!

MARK ANDREWS
15.11.17, 21:32

thanks

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions