Answers for "can you use rand to read in from an external file inc++"

C++
0

can you use rand to read in from an external file inc++

string line;
int random = 0;
int numOfLines = 0;
ifstream File("file.txt");

    srand(time(0));
    random = rand() % 50;

while(getline(File, line))
{
    ++numOfLines;

    if(numOfLines == random)
    {
        cout << line;
    }

}
Posted by: Guest on May-03-2020

Code answers related to "can you use rand to read in from an external file inc++"

Browse Popular Code Answers by Language