fork(123) download
  1. // file XOR test 4 (needs newer boost than what ideone.com has)
  2. #include <iostream>
  3. #include <string>
  4. #include <fstream>
  5. #include <boost/filesystem.hpp>
  6. #include <boost/iostreams/device/mapped_file.hpp>
  7. void XOR(const std::string& filePath, const std::string& outputPath, const std::string& key)
  8. {
  9. boost::iostreams::mapped_file_source in(filePath);
  10. boost::iostreams::mapped_file_sink out(outputPath);
  11.  
  12. for(std::size_t pos = 0; pos < in.size(); ++pos)
  13. out.data()[pos] = in.data()[pos] ^ key[pos % key.size()];
  14. }
  15. int main()
  16. {
  17. XOR("test.bin", "test.out", std::string(32, '*'));
  18. std::cout << "File size: " << boost::filesystem::file_size("test.bin") << '\n';
  19. }
  20.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/include/boost/iostreams/device/mapped_file.hpp: In function ‘void XOR(const std::string&, const std::string&, const std::string&)’:
/usr/include/boost/iostreams/device/mapped_file.hpp:200: error: ‘char* boost::iostreams::mapped_file::data() const’ is inaccessible
prog.cpp:13: error: within this context
prog.cpp:13: error: ‘boost::iostreams::mapped_file’ is not an accessible base of ‘boost::iostreams::mapped_file_sink’
stdout
Standard output is empty