TPIE

2362a60
Reading and writing file streams

The central class in TPIE for reading from files and writing to files is the file_stream class.

It reads and writes primitives and primitive structures to files.

#include <tpie/file_stream.h>
#include <string>
using namespace tpie;
using namespace std;
struct segment_t {
double x1, y1, x2, y2;
float z1, z2;
};
void copystream(const string & infile, const string & outfile) {
in.open(infile);
out.open(outfile);
while (in.can_read()) {
segment_t item = in.read();
out.write(item);
}
}

The main methods of interest are tpie::file_stream::open(), tpie::file_stream::close(), tpie::file_stream::read(), tpie::file_stream::write(), tpie::file_stream::seek().

By default, tpie::file_stream reads and writes blocks of size 2 MB at a time. You can change this by passing a block factor to the constructor of file_stream.