In de rapte en dus verre van perfect.
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
string filename;
char c;
srand((unsigned)time(NULL));
cout << endl << "Naam van het bestand: ";
cin >> filename;
cout << endl;
ifstream d_file;
d_file.open(filename.c_str());
if (!d_file.is_open())
{
cout << "Bestand " << filename << " bestaat niet." << endl;
exit(1);
}
else
{
//prints the number of lines in a file
string t;
int lines = 0;
int random = 0;
while(getline(d_file, t, '\n'))
{
++lines;
}
cout << "Aantal lijnen in het bestand: " << lines << endl;
random = (rand() % lines) + 1;
cout << "Random getal: " << random << endl;
for (int i = 1; i < random; i++)
{
getline(d_file, t, '\n');
}
cout << "Random lijn: " << t << endl;
}
d_file.close();
return 0;
}