Advertisement
spacechase0

FileToArray

Oct 27th, 2012
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <fstream>
  2. #include <iomanip>
  3. #include <sstream>
  4.  
  5. // http://www.sfml-dev.org/forum/viewtopic.php?t=5996
  6. int main(int argc, char** argv)
  7. {
  8.     if (argc <= 2)
  9.         return -1;
  10.  
  11.     std::ifstream in(argv[1], std::ios::binary);
  12.     std::ofstream out(argv[2]);
  13.  
  14.     out <<"const char data[] = { ";
  15.  
  16.     char c = 0;
  17.     while ( in.read( &c, 1 ) )
  18.     {
  19.         std::stringstream ss;
  20.         ss << std::hex << std::setfill( '0' ) << std::setw( 2 ) << std::setprecision( 2 ) << static_cast< short >( c );
  21.        
  22.         out << "0x" << ss.str().substr( ss.str().length() - 2 ) << ", ";
  23.     }
  24.  
  25.     out << "};";
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement