c++ - How do I know I reached a file's maximum size when using ofstream? - TagMerge
3How do I know I reached a file's maximum size when using ofstream?How do I know I reached a file's maximum size when using ofstream?

How do I know I reached a file's maximum size when using ofstream?

Asked 1 years ago
5
3 answers

First off, maximum file size is a filesystem limit, not an Operating System limit. It will even vary for a particular filesystem, based on how the filesystem was formatted.

As for how you'd figure out that you'd reached the limit, your code will likely throw an exception when that happens, which you'll then be able to relate back to the OS error codes.

Note that the actual limit is pretty darn big for a "typical" EXT2 filesystem - in the Terabytes. You'll likely never reach it, in practice. If you seriously are accumulating Terabytes of data, you might want to consider whether there's a more reasonable way to store it, rather than a single gigantic file.

Source: link

4

You can check if the bad bit is set. Also, using exceptions you can force the stream to throw an exception, when the bad bit gets set.

Source: link

0

I think (not 100% sure) that you'd just have to compare the stream's current size after a write to whatever the OS's max file size is. Otherwise I'm guessing the underlying implementation will just let you keep writing until the actual OS io calls fail.

Source: link

Recent Questions on c++

    Programming Languages