Primitive I/O


You can write and read primitives like an int or a double using the Universal Streaming Service.

Example <ospace/stream/examples/primio1.cpp>
#include <fstream>
#include <ospace/stream.h>

void
write()
  {
  fstream file( "primio1.bin", ios::binary | ios::out | ios::trunc );
  os_bstream stream( os_adapter_for( file ) );

  cout << "Write 5, 3.141" << endl;
  stream << 5 << 3.141; // Write two primitives in binary format.
  }

void
read()
  {
  fstream file( "primio1.bin", ios::binary | ios::in );
  os_bstream stream( os_adapter_for( file ) );

  int i;
  double d;
  stream >> i >> d; // Read back two primitives.
  cout << "Read " << i << ", " << d << endl;
  }

void
main()
  {
  os_streaming_toolkit initialize;
  write();
  read();
  }

Write 5, 3.141
Read 5, 3.141
  

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.