c# - Filestream seeks correct position whereas fstream doesn't -
in c#
filestream fs("file.bin",/*open in binary, read mode*/); var bytes = new byte[100]; fs.seek(20000000, seekorigin.begin); //*20000000* fs.read(bytes, 0, 100);
in c++, istream
becomes null
typedef std::shared_ptr<boost::iostreams::mapped_file_source> filestream; filestream fs = filestream(new boost::iostreams::mapped_file_source("file.bin", 100, 0)); if (fs->is_open()) { boost::iostreams::stream<boost::iostreams::mapped_file_source> is(*fs.get()); if (is.seekg(20000000, is.beg)) //read 100 characters 20000000th position fs->close(); }
if change boost::iostreams::stream<boost::iostreams::mapped_file_source> is(*fs.get());
into boost::iostreams::stream<boost::iostreams::mapped_file_source> is("file.bin");
is
initialized reading 20000000th
byte still impossible. error occurs same when file specified isn't found.
you excplicitly telling mapped_file_source
maximum file size mapped 100 bytes. why think go position 20000000 , read anything?
see reference on mapped_file_source
overview: default, files must exist before being opened, , not truncated; attempting write past end of file results in error.
constructor documentation: length - number of bytes map. if parameter not specified, entire file mapped.
Comments
Post a Comment