DumpBinary

stdafx.h

#include "targetver.h"

#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstdlib>

main.cpp


#include "stdafx.h"

int main(int argc, char *argv[])
{
#if 0
	if (argc != 3)
	{
		return 0;
	}
	std::fstream fs(argv[1], std::ios::binary | std::ios::trunc | std::ios::in | std::ios::out);
#endif
	std::fstream in("D:\\axhelper.exe", std::ios::binary | std::ios::in);
	if (!in.is_open())return 1;
	//至文件尾获取文件大小
	in.seekg(0,std::ios::end);
	std::streamoff inSize = in.tellg();
	std::cout << "文件大小:" <<inSize << std::endl;
	//至文件头
	in.seekg(0, std::ios::beg);
	//分配内存
	char *buff = (char*)std::calloc((size_t)inSize, sizeof(char));

	//释放内存
	std::free(buff);
	in.close();

	getchar();
	//fs.read()
    return 0;
}

posted @ 2018-03-21 19:47  學海無涯  阅读(196)  评论(0编辑  收藏  举报