#include "stdafx.h"
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int printHex(wstring fileName) {
wcout << fileName << endl;
ifstream ifs;
ifs.open(fileName, ios::binary);
if (ifs.is_open()) {
cout << "File opened." << endl;
} else {
cout << "File can't be opened." << endl;
return 1;
}
long beginPos = 0;
ifs.seekg (0, ios::end);
streamoff endPos = ifs.tellg();
streamoff fileSize = endPos - beginPos;
cout << "size is: " << fileSize << " bytes.\n";
char *memblock = new char[(unsigned int) fileSize];
ifs.seekg (0, ios::beg);
ifs.read (memblock, fileSize);
ifs.close();
int i;
for (i = 0; i < fileSize; i++) {
char c = memblock[i];
cout << setw(4) << hex << (int)(0xff & c);
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
wstring fileName = argv[argc <= 1 ? 0 : 1];
return printHex(fileName);
}
'Programming' 카테고리의 다른 글
(C#) Play Sound Files using libZPlay (0) | 2012.06.07 |
---|---|
libZPlay: Easy way to play mp3, ogg, ac3, flac, aac, wav and pcm files in your Win32 application (0) | 2012.06.07 |
[ Mac ] XCode no! gcc yes! - Command Line Tools for XCode (0) | 2012.06.05 |
(C) fseek - Moves the file pointer to a specified location (0) | 2012.06.05 |
(C++) difftime (0) | 2012.06.05 |