Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <time.h>
- #include <stdlib.h>
- using namespace std;
- int main ()
- {
- int number_of_lines = 0;
- string line;
- ifstream myfile("abc.txt");
- if(!myfile.is_open()) return 0;
- while(getline(myfile, line)) number_of_lines++;
- srand(time(NULL));
- int rand_val = rand() % number_of_lines + 1;
- myfile.clear();
- myfile.seekg (0, myfile.beg);
- for(int i = 0; i < rand_val; i++) getline(myfile, line);
- cout << line << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement