ToniDev

Lab8/ex.1

Jan 4th, 2022
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <fstream>
  5. #include <set>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     ifstream fin("intrare.txt");
  11.     ofstream fout("iesire.txt");
  12.  
  13.     if (!fin.is_open())
  14.     {
  15.         cout << "Nu s-a gasit fisierul.";
  16.         return -1;
  17.     }
  18.  
  19.  
  20.     set<string> mySet;
  21.     set<string>::iterator mySetIterator;
  22.  
  23.     string cuvant, linie;
  24.  
  25.     while (!fin.eof())
  26.     {
  27.         getline(fin, linie);
  28.  
  29.         stringstream ss(linie);
  30.  
  31.         while (!ss.eof())
  32.         {
  33.             ss >> cuvant;
  34.             mySet.insert(cuvant);
  35.         }
  36.     }
  37.  
  38.     for (mySetIterator = mySet.begin();  mySetIterator != mySet.end(); ++mySetIterator)
  39.     {
  40.         fout << *mySetIterator << " ";
  41.     }
  42.  
  43.     fin.close();
  44.     fout.close();
  45.  
  46.     cout << "Gata. verifica fisierul.";
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment