リファラ
http://www.google.co.jp/search?q=%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%80%80%EF%BC%91%EF%BC%96%E9%80%B2%E3%83%80%E3%83%B3%E3%83%97+C%2B%2B&hl=ja&lr=&ie=UTF-8&start=30&sa=N
これで 3件も来てるので結構せっぱつまってるんでしょうか。C++ でやるんだったらこんな感じ? エラー処理とかは考えない方向で。
#include <iostream> #include <fstream> using namespace std; int main(int argc, char** argv) { ifstream in(argv[1], ios::binary); char ch = '\0'; while (in.get(ch)) { cout << hex << "0x" << (int)ch << " "; } in.close(); return 0; }
ついでに Java の場合。
import java.io.*; public class Dump { public static void main(String[] args) throws Exception { InputStream in = new FileInputStream(args[0]); for (int n = in.read(); n != -1; n = in.read()) { System.out.print("0x" + Integer.toHexString(n) + " "); } in.close(); } }
あと Ruby の場合。
File.open(ARGV[0], "rb"){|f| f.read().each_byte{|n| print format("0x%x ", n) } }
Groovy ならこんな感じ? あんまりよくわかってないけど。
new java.io.FileInputStream("a.txt").withStream{in| n = in.read() while (n != -1) { print("0x"+ java.lang.Integer.toHexString(n) +" ") n = in.read() } }
わー、久しぶりに日記にコード載せちゃったよ。えへへ。