Witam. Chciałbym losować linie z plku txt
tzn. By pokazywało takie cos z zestawu pytan losowo
LINIE:
1.pytanie
2.odp a
3 odp b
4 odp c
5 odp d
Mam taki kod ale pokazuje mi błędy i wyświetla tylko 1 linię póki co:
#include <iostream>
#include <fstream>
#include <string>
#include <time.h>
#include <stdlib.h>
using namespace std;
int main ()
{
int number_of_lines [3]={1,2,3};
string line;
ifstream myfile("quiz.txt");
if(!myfile.is_open()) return 0;
while(getline(myfile, line)) number_of_lines++;
srand(time(NULL));
int rand_val = rand() % number_of_lines;
myfile.clear();
myfile.seekg (0, myfile.beg);
for(int i = 0; i < rand_val; i++) getline(myfile, line);
cout << line << endl;
system("pause");
}