#include "FileTools.h" #include #include void FileTools::ExtractWordsFromFile(const string& iFilePath, vector& oWords) { ifstream wordList; wordList.open(iFilePath); if (wordList.is_open()) { string word; while (getline(wordList, word)) { // TODO basic checks on the words to validate/sanitise the input if (!word.empty()) { oWords.push_back(word); } } wordList.close(); } } void FileTools::SaveRseult(const vector& iWords, const string& iPath, bool isReverse) { fstream fileOut; fileOut.open(iPath, ios_base::out); if (fileOut.is_open()) { if (isReverse) { for (auto wordsIt = iWords.rbegin(); wordsIt != iWords.rend(); ++wordsIt) { fileOut << *wordsIt << "\n"; } } else { for (auto wordsIt = iWords.begin(); wordsIt != iWords.end(); ++wordsIt) { fileOut << *wordsIt << "\n"; } } } fileOut.close(); }