Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <ctime>
- #include <stdlib.h>
- using namespace std;
- string s1;
- string s2;
- string s3;
- string s5;
- void write();
- void read();
- int random();
- int main() {
- read();
- string s4;
- cout << "Write to the file (Y/N): ";
- cin >> s4;
- if(s4 == "Y" || s4 == "y" || s4 == "Yes" || s4 == "yes") {
- write();
- } else if(s4 == "N" || s4 == "n" || s4 == "No" || s4 == "no") {
- random();
- } else {
- cout << "Wrong input!" << endl;
- }
- }
- void write() {
- ofstream file ("file.txt");
- cin >> s1 >> s2;
- s3 = s1 + " " + s2;
- file << s3;
- }
- void read() {
- ifstream file ("file.txt");
- if(file.is_open()) {
- while(file.good()) {
- getline(file, s5);
- cout << s5 << endl;
- }
- file.close();
- }
- }
- int random() {
- srand(time(NULL));
- ifstream file("file.txt");
- int r1;
- if(file.is_open()) {
- while(file >> s1 >> s2) {
- }
- file.close();
- }
- for(int i = 0; i<3; i++) {
- r1 = rand() % 2 + 1;
- if(r1 == 1) {
- cout << s1 << endl;
- } else if(r1 == 2) {
- cout << s2 << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment