Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. void transfer(char symbol, std::string first, std::string second) {
  6.     std::ifstream file(first);
  7.     std::ofstream output(second, std::ios::out | std::ios::trunc);
  8.    
  9.     if (!file.is_open() || !output.is_open()) return;
  10.  
  11.     std::string line;
  12.     while (true) {
  13.         int i = file.get();
  14.        
  15.         if (i <= 0) break;
  16.  
  17.         char c = (char)i;
  18.  
  19.         line += c;
  20.  
  21.         if (c == '\n') {
  22.             if (std::find(line.begin(), line.end(), symbol) != line.end())
  23.                 output << line;
  24.             line.clear();
  25.         }
  26.     }
  27.  
  28.     file.close();
  29.     output.flush();
  30.     output.close();
  31. }
  32.  
  33. int main() {
  34.     transfer('0', "hello.txt", "world.txt");
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement