13樓 巨大八爪鱼
2016-1-26 20:56
ofstream file("example.rxdata", ios::binary); RubyMarshal rms(&file); rms.WriteHeader(); /*rms.BeginArray(4); rms.WriteFixnum(-23489); rms.WriteString("Do you want anything to drink?\nA cup of milk, please."); rms.BeginHash(2, true); rms.WriteBool(false); rms.WriteString("test"); rms.WriteString("haha"); rms.WriteSymbol("sym"); rms.WriteString("Default Value");
rms.BeginArray(6); rms.WriteBool(true); rms.WriteBool(false); rms.WriteNil(); rms.WriteRegexp("/^here$/mi"); rms.WriteSymbol("sym2"); rms.WriteSymLink(1);*/
/*rms.BeginObject("A", 2); rms.BeginMember("b"); rms.BeginArray(2); rms.WriteModule("Math"); rms.WriteNil(); rms.BeginMember("a"); rms.WriteRegexp("/./im");*/ //rms.WriteClass("A");
/*rms.BeginExtended("Math"); rms.WriteString("rest");*/ /*rms.BeginObject("A", 2); rms.BeginMember("b"); rms.WriteString("space"); rms.BeginMember("a"); rms.WriteString("time");*/ //cout << rms.WriteBignum(-2015104222256789012) << endl; cout << rms.WriteFloat(-3.14159265358979323846) << endl;
file.close();
ifstream file2("example.rxdata", ios::binary); char list[] = "0123456789ABCDEF"; char ch; int i; for (i = 0; ch = file2.get(), !file2.eof(); i++) { cout << list[ch >> 4 & 0x0f] << list[ch & 0x0f] << ' '; if ((i + 1) % 16 == 8) cout << ' '; if ((i + 1) % 16 == 0) { i = -1; cout << endl; } } cout << endl; file2.close(); system("pause"); return 0;
|