Revision: 863
http://assorted.svn.sourceforge.net/assorted/?rev=863&view=rev
Author: yangzhang
Date: 2008-07-01 23:41:27 -0700 (Tue, 01 Jul 2008)
Log Message:
-----------
added binary IO demo
Added Paths:
-----------
sandbox/trunk/src/cc/binaryio.cc
Added: sandbox/trunk/src/cc/binaryio.cc
===================================================================
--- sandbox/trunk/src/cc/binaryio.cc (rev 0)
+++ sandbox/trunk/src/cc/binaryio.cc 2008-07-02 06:41:27 UTC (rev 863)
@@ -0,0 +1,24 @@
+#include <iostream>
+#include <fstream>
+using namespace std;
+int main() {
+ ofstream os;
+ double data = 534.663;
+ os.open("outfile", ios::out | ios::trunc | ios::binary);
+ if (os.is_open()) {
+ os.write(reinterpret_cast<char*>(&data), sizeof(data));
+ os.close();
+ }
+
+ ifstream is;
+ double data2 = 0;
+ is.open("outfile", ios::in | ios::binary);
+ if (is.is_open()) {
+ is.read(reinterpret_cast<char*>(&data2), sizeof(data2));
+ is.close();
+ }
+
+ cout << data2;
+
+ return 0;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|