56 lines
1.1 KiB
C++
56 lines
1.1 KiB
C++
#include <iostream>
|
|
#include <fstream>
|
|
#include <vector>
|
|
using namespace std;
|
|
|
|
static int write_file(const std::string & fname, std::vector<char>& buf)
|
|
{
|
|
std::ofstream fs(fname, std::ios::binary | std::ios::out);
|
|
if(!fs.good())
|
|
{
|
|
std::cerr<<fname<<" does not exist"<<std::endl;
|
|
return -1;
|
|
}
|
|
for(char c : buf) {
|
|
fs << (int)((unsigned char)c) << ",";
|
|
}
|
|
fs.close();
|
|
return 0;
|
|
}
|
|
|
|
static int load_file(const std::string & fname, std::vector<char>& buf)
|
|
{
|
|
std::ifstream fs(fname, std::ios::binary | std::ios::in);
|
|
if(!fs.good())
|
|
{
|
|
std::cerr<<fname<<" does not exist"<<std::endl;
|
|
return -1;
|
|
}
|
|
|
|
fs.seekg(0, std::ios::end);
|
|
int fsize=fs.tellg();
|
|
|
|
fs.seekg(0, std::ios::beg);
|
|
buf.resize(fsize);
|
|
fs.read(buf.data(),fsize);
|
|
fs.close();
|
|
return 0;
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
if(argc < 3) {
|
|
cout << "please input the model file and mem file name" << endl;
|
|
return -1;
|
|
}
|
|
|
|
vector<char> content;
|
|
load_file(argv[1], content);
|
|
if(content.size() <= 0) {
|
|
cout << "do not read any content" << endl;
|
|
return -1;
|
|
}
|
|
write_file(argv[2], content);
|
|
return 0;
|
|
}
|