How to implement array-based listing and searching?

Background: I'm trying to open a text file from my computer and randomly output a random line of text (string) onto the console. How do I go about doing this?
So for example, if my text file, "StringTextFile.txt" had 50 rows of strings datas (not integers or chars), how would I randomly generate a line of word from the 50 rows of words in the StringTextFile.txt and output it onto the console?

This is how far I've gotten, which isn't much, but somewhere. I don't even know if my code even makes sense, at this point I'm just randomly shoving code together.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <fstream>
#include <iostream>
#include <string>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

//main
int main()
{
    //variables
    int randomNumber = rand() % 50 + 1; // seeding random number from [1 - 50]
    int input[200]; // maximum capacity of array
    

    //opening file for input
    ifstream fin;
    fin.open("StringTextFile.txt");
    if (!fin.good()) throw "I/O Error.";

    //creating empty list
    const int MAX_STRINGTEXTS = 200; // list capacity
    int nSTRINGTEXTS = 0; // initially empty score
    int song[MAX_STRINGTEXTS]; // the array


    while (!fin.good())
    {
        string STRINGTEXTS[50]; // number of songs in songs.txt

        for (int i = 0; i < 50; i++) // the number of rows in StringTextFile.txt (50)
        {
            randomNumber;
            getline(fin, STRINGTEXTS[i]);  //retrieving a random line from the 50 lines of text in StringTextFile.txt
            cout << STRINGTEXTS[i]; //outputting the randomly generated numbered, text onto the console.
        } // for loop
    } //while loop
    fin.close(); //closing text file
} // main 


Constructive Criticism is highly appreciated!
Would you please explain line 36?

I think I do not really understand your job? What exactly do you want to do? Getting randomly any one of 50 lines from a text file an write it on standard output? But your program only copies 50 input lines to standard output.
Topic archived. No new replies allowed.