Advertisement
Baxram97

Untitled

Mar 17th, 2022
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4.  
  5. std::string myEof(std::ifstream &stream) {
  6.     std::string ans;
  7.     if (!stream) {
  8.         std::cout << "File not found\n";
  9.     } else {
  10.         char ch;
  11.         while (!stream.eof()) {
  12.             stream.get(ch);
  13.             ans.push_back(ch);
  14.             if (!stream.eof()) std::cout << ch;        //eof   -   end of file, returns bool val
  15.  
  16.         }
  17.         stream.close();
  18.     }
  19.     return ans;
  20. }
  21.  
  22. void put(char *name, std::string data) {
  23.     std::ofstream out(name, std::ios::out | std::ios::binary);
  24.     if (!out) std::cout << "File not found\n";
  25.     else {
  26.         int i = 0;
  27.         while (i < data.size()) {
  28.  
  29.             out.put(data[i]);
  30.             i++;
  31.         }
  32.     }
  33.     out.close();
  34. }
  35.  
  36.  
  37. int main() {
  38. //    std::ofstream out1("Word.bin", std::ios::out | std::ios::binary);
  39. //    put("Word.bin",
  40. //        "Tron\nShusha\nZamanov\nMoquda\nboss\nmain\nScooby\nvoid\nShamakhi\nKiev\nBaku\nLeon\nstep\nroot\nSuleyman\nBaku\nMaide\n");
  41. //     std::ifstream in("Word.bin", std::ios::in | std::ios::binary);
  42. //     std::string get = myEof(in);
  43. //     std::cout<<'\n';
  44. //     for(int i = 0;i<get.size();i++){
  45. //         get[i] = ~get[i];
  46. //     }
  47. //     std::ifstream out("Word.bin", std::ios::out | std::ios::binary);
  48. //     put("Word.bin", get);
  49.  
  50.  
  51.     std::ifstream in2("Word.bin", std::ios::in | std::ios::binary);
  52.     std::string get2 = myEof(in2);
  53.     std::cout << '\n';
  54.     for (int i = 0; i < get2.size(); i++) {
  55.         std::cout << (char) ~get2[i];
  56.     }
  57.  
  58.     return 0;
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement