Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <string>
- #include <array>
- #include <fstream>
- #include <string_view>
- using namespace std::literals;
- // напишите эту функцию
- inline bool DecodeRLE(const std::string& src_name, const std::string& dst_name) {
- std::ifstream in_file(src_name, std::ios::binary);
- if (!in_file) {
- std::cerr << "Can't open input file"sv << std::endl;
- return false;
- }
- std::ofstream out_file(dst_name, std::ios::binary);
- if (!out_file) {
- std::cerr << "Can't open output file"sv << std::endl;
- return false;
- }
- std::array<char, 1024> buffer;
- do {
- int c = in_file.get();
- unsigned char header = static_cast<char>(c);
- int block_type = (header & 1);
- int data_size = (header >> 1) + 1;
- if (!block_type) {
- in_file.read(buffer.data(), data_size);
- out_file.write(buffer.data(), in_file.gcount());
- }
- else {
- c = in_file.get();
- unsigned char ch = static_cast<char>(c);
- out_file << std::string(data_size, ch);
- }
- } while (in_file);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment