Почему не записывает в файл?

#include <algorithm>
#include <iostream>

#include <fstream>

int main(int argc, char** argv)
{
   std::string input_file;
   std::string output_file;
   int skip_bytes = 0;
   int header_bypte_skip = 0;
   if ((argc <= 1) || (argv[argc - 1] == nullptr) || (argv[argc - 1][0] == '-'))
   {
       std::cerr << "No argument provided!" << std::endl;
   }
   else
   {
       input_file = std::string(argv[1]);
       output_file = std::string(argv[2]);
       skip_bytes = std::atoi(argv[4]);
       header_bypte_skip = std::atoi(argv[5]);
   }

   std::ifstream input(input_file, std::ios::binary);
   std::ofstream output(output_file);

   char* sequence = argv[3];
   const size_t sequence_len = std::strlen(reinterpret_cast<char*>(sequence));

   std::ostream_iterator<char> ostream_it(output, " ");
   std::istream_iterator<char> it(input);
   std::istream_iterator<char> eof;

   int count = 0;
   std::advance(it, header_bypte_skip);
   while (it != eof)
   {
       
       auto it2 = std::search(it, eof, sequence, sequence + sequence_len);
       
       size_t len = std::distance(it, it2);
       size_t len2 = std::distance(it2, it);
       //std::copy(it, it + len, std::ostream_iterator<char>(output, ""));
       it = it2;
   }
   std::cout << "crop: " << count;
}

пытаюсь прочиать файл, вырезать из него все лишнее и записать в другой файл. Когда я делаю std::copy(it, it + len, std::ostream_iterator<char>(output, ""));

файл не записывается, и видимо поиск не правильно написан, дистанс между итератарами равен нулю, как так? хотя вроде серч ставит на нужный элемент..


Ответы (0 шт):