C++ FileSize() function By Christopher Diggins. Finding the size of the file in C++ in a portable manner is not trivial! | C++ Windows MFC, Win32, VS Dev Posted: 9 Dec 2004 Updated: 15 Dec 2004 Views: 48,158 |
Announcements |
| ||||||||||||||||||
IntroductionThe C++ standard library doesn't have a The reason is that the size of a file is only really accessible through the operating system. C++ was written to assume as little about the platform as possible, including whether or not there is an operating system with a file system. Yeah, I know, my reaction is the same as yours, but nonetheless, we must carry onward brave programmer, and get the job done. Compiler Specific: Visual C++The following contribution by Jesse Chisholm works very well if you will only ever be compiling with Visual C++: #include Pitfalls:
Non-Portable Version: stat()Many C++ compilers provide the C run-time function #include Pitfalls:
Portable Version: ifstream::tellg()The following is kind of a defacto standard I use, and which I have seen often, with variations: #include Pitfalls:
If you can live with that, which I usually can, then great! Otherwise, there is another option. Using BoostThere is a better solution, if you have the Boost C++ library installed which provides us with the following function: #include Pitfalls:
More information on |
没有评论:
发表评论