Hi. I am new to the forum and I had a question. I have looked around and haven't really been able to find exactly what I am looking for.
I am looking for the code in C++ to read in a random single line with spaces from a file.
This is the file I have...(example.txt)
the big green
forrest gump
blades of glory
glory road
animal house
pirates of the carribean
the seven little foys
the lord of the rings
the green mile
cast away
star wars
it
now and then
the princess bride
This is the code for a function I have so far, but it just prints out the entire file.
void file(){
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while (! myfile.eof())
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
}
how do i change this so that it reads in just a random single line?