Created
July 31, 2021 10:31
-
-
Save afifabroory/47008ed10ea84361d5b3f064bd9b2863 to your computer and use it in GitHub Desktop.
My solution for ods exercises 1.1 (4)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <functional> | |
#include <set> | |
using namespace std; | |
void read_input(string fileName, set<string,not_equal_to<string>>& setText); | |
void write_input(set<string,not_equal_to<string>> setText); | |
int main(void) | |
{ | |
const string fileName = "HelloWorld.txt"; | |
set<string,not_equal_to<string>> textLine; | |
read_input(fileName, textLine); | |
write_input(textLine); | |
} | |
void read_input(string fileName, set<string,not_equal_to<string>>& setText) | |
{ | |
ifstream myFile(fileName); | |
string textLine; | |
while (getline(myFile, textLine)) { setText.emplace(textLine); } | |
} | |
void write_input(set<string,not_equal_to<string>> setText) | |
{ | |
for (set<string,not_equal_to<string>>::reverse_iterator it = setText.rbegin(); it != setText.rend(); ++it) | |
{ | |
cout << *it << endl; | |
} | |
cout << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment