Skip to content

Instantly share code, notes, and snippets.

@afifabroory
Created July 31, 2021 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afifabroory/47008ed10ea84361d5b3f064bd9b2863 to your computer and use it in GitHub Desktop.
Save afifabroory/47008ed10ea84361d5b3f064bd9b2863 to your computer and use it in GitHub Desktop.
My solution for ods exercises 1.1 (4)
#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