Hello, so I'm fairly new to C++ but not to programming overall. I have created a simple TXT file with about 15 words in them, and I would like to write a program which asks me for a number of words, you type it in (simple cout, cin) and it gets the number of words you selected randomly from my text files and outputs them.
So the program would be like:
How many words would you like?
user: 6
program: selects 6 random words from TXT file and prints them on screen.
I hope this makes sense, and I would be happy to provide more information if needed
How do I start? I know how to open files, but how do I take the contents of the files and be able to randomly select words from them? I would like to put the file contents into an array to be able to access them quickly. How do I do that?
what I would do is use the function getline, or simply get, and pull it into a 2-dimension array. then use rand() pull out x amount of words from the 2d array.
some pseudo code.
1 2 3 4 5 6
//this is for the random selection of words
get x from user
seed rand
for 1 to x
string out equals string at random number 0 to end of 2D array /*this would be about 15 in your case*/
hope this helps get you started, feel free to ask more questions if need be.