#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
struct AscendingOrderSorter
{
bool operator()(const std::string& lhs, const std::string& rhs)
{
return lhs < rhs;
}
};
struct DecsendingOrderSorter
{
bool operator()(const std::string& lhs, const std::string& rhs)
{
return lhs > rhs;
}
};
struct RowPrinter
{
void operator()(const std::string& value)
{
std::cout << value << "\n";
}
};
int main(int argc, char *argv[])
{
std::ifstream input_file("D:\\123.txt");
std::string value;
std::vector<std::string> file_data;
if (input_file)
{
while (!input_file.eof())
{
std::getline(input_file, value, '\n');
file_data.push_back(value);
}
}
std::cout << "Before sort: \n";
std::sort(file_data.begin(), file_data.end(), AscendingOrderSorter());
std::cout << "After sort: \n";
std::for_each(file_data.begin(), file_data.end(), RowPrinter());
}