Código
#include<string> // std::string #include<vector> // std::vector<> #include<iostream> // std::cout | std::cin | std::cerr #include<fstream> // std::ifstream | std::ofstream #include<cstdlib> // std::exit() #include<algorithm> // std:: sort() #include <locale> #include <cctype> using namespace std; vector<string> load_vector(const string&); void save_vector(const vector<string>&, const string&); void error(const string&); int main() { string filename2 = "data2.txt"; //locale loc; string filename = "data.txt"; vector<string> text = load_vector(filename); sort(text.begin(), text.end()); text.erase(unique(text.begin(), text.end()), text.end()); //for (unsigned int i=0; i<text.size(); i++) { // text [i] = tolower (text[i], loc); // } save_vector(text, filename2); return 0; } vector<string> load_vector(const string& filename) { vector<string> vi; ifstream ifile {filename}; if (!ifile) error("load_vector cannot open the file " + filename); copy(istream_iterator<string>(ifile), istream_iterator<string>(), back_inserter(vi)); return vi; } void save_vector(const vector<string>& vi, const string& filename2) { ofstream ofile ("data2.txt"); if (!ofile) error("save_vector cannot open the file " + filename2); for (auto n : vi) ofile << n << ' '; ofile.close(); cout << "\nVector written in file \"" << filename2 << "\"" << endl; } void error(const string& s) { cerr << "Error: " << s << endl; exit(EXIT_FAILURE); }