c++ - Can a std::ifstream/FILE* change size? -



c++ - Can a std::ifstream/FILE* change size? -

say have next code (which opens file, gets size, , reads in 1 go):

std::ifstream file(path, std::ios_base::binary | std::ios_base::ate); std::istream::streampos file_size = file.tellg(); file.seekg(0); char* buffer = new char[file_size]; file.read(buffer, file_size);

is possible file alter size in between file.tellg() , file.read() calls (i.e. programme modifies file)? is, if file.read() succeeds, guaranteed file.gcount() == file_size?

and extending c* (i.e. doing fopen("rb"), fseek(), ftell(), rewind(), fread()), if fread() succeeds, homecoming file size (as reported ftell())?

i'm leaning towards beingness implementation defined, i'm curious if c++ standard (or c standard, c++ standard refers file-related functions) makes guarantees here or not.

*i'm working in c++, , there 2 ways me work files: std::fstream , file*. c++ standard defers c standard regarding file* functions, why bring c explicitly here.

i rather think dependant on type of file have open , abilities of operating system.

for read not behave expect, file have had have shrunk between ftell , fread. have process ftruncate. , can't find says happens other processes have file open. i'd not expect them able read info used there.

c++ c

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -