I have done it using reference, my code below :
std::vector get_bytes( const std::string& in_file_name )
{
std::ifstream file( in_file_name, std::ios::binary ) ;
using iterator = std::istream_iterator ;
return { iterator(file), iterator{} } ;
}
void put_bytes( const std::vector& bytes, const std::string& out_file_name )
{
std::ofstream file( out_file_name, std::ios::binary ) ;
for( unsigned char c : bytes ) file.put(c) ;
}
std::vector& convert( std::vector& bytes )
{
// static_assert( std::numeric_limits::max() > 254, "out of range" ) ;
for( unsigned char& c : bytes ) c = 255 - c ;
return bytes ;
}
int main( int argc, char* argv[] )
{
if( argc != 3 )
{
std::cerr << "usage: " << argv[0] << " \n" ;
return 1 ;
}
const std::string in_file_name = argv[1] ;
const std::string out_file_name = argv[2] ;
auto vec = get_bytes(in_file_name) ;
put_bytes( convert(vec), out_file_name ) ;
std::cout << "input file '" << in_file_name << " was converted. output file '"
<< out_file_name << "'\n" ;
}
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
The above code was figured out by someones help