Advertisement
Leeen

Lab for Bezus №4 (9 var)

Nov 26th, 2018
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<string>
  4.  
  5. using namespace std;
  6.  
  7. string changeS(string s1)
  8. {
  9.     int size = s1.size() - 3;
  10.     string s2 = s1.substr(0, size);
  11.         s2 = s2 + "***";
  12.     return s2;
  13. }
  14.  
  15. int main()
  16. {
  17.     cout << "Input a word range>";
  18.     int range;
  19.     cin >> range;
  20.  
  21.     ifstream fileIn;
  22.     fileIn.open("input.txt");
  23.     if (!fileIn.is_open())
  24.         cout << "Error, file 'intput.txt' not found";
  25.    
  26.  
  27.     ofstream fileOut;
  28.     fileOut.open("output.txt");
  29.     //if (!fileOut.open)
  30.     //  cout << "Error, file 'output.txt' not found";
  31.  
  32.     string s1;
  33.     string s2;
  34.  
  35.     while (!fileIn.eof())
  36.     {
  37.         fileIn >> s1;
  38.         if (s1.size() > range)
  39.             s2 = changeS(s1);
  40.         else
  41.             s2 = s1;
  42.         fileOut << s2 + ' ';
  43.     }
  44.     fileIn.close();
  45.     fileOut.close();
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement