Advertisement
Guest User

Evil Azrael

a guest
Feb 4th, 2010
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <string>
  5. #include <iomanip>
  6. using namespace std;
  7.  
  8. void readfile(char *name, string &content, int &size)
  9. {
  10.    ostringstream out;
  11.    ifstream in(name);
  12.    size = 0;
  13.    
  14.    if(!in.good())
  15.      throw "Error!";
  16.    while(1)
  17.      {
  18.    
  19.     unsigned char  value = 0;
  20.     in.read((char*) &value, 1);
  21.     if(in.eof())
  22.       break;
  23.     size++;
  24.     if(value < 32 || value > 127)
  25.          out << "\\" << oct << setfill('0') << setw(3) << (int) value;
  26.     else if(value == '\\')
  27.         out << "\\\\";
  28.     else
  29.         out << (char) value;
  30.     if((size % 30) == 0)
  31.       out << "\"" << endl << "\"";
  32.      }
  33.    content = out.str();
  34. }
  35.  
  36. int main(int argc, char **argv)
  37. {
  38.    string content = "";
  39.    int size = 0;
  40.    readfile(argv[2], content, size);
  41.    cout << "#include \"linkedinfile.h\"" << endl;
  42.    cout << "LinkedInFile " << argv[1] << " = {" << size
  43.      << ", " << endl << "\""  << content << "\"};" << endl << endl;
  44.    cout << flush;
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement