How to get file size using boost::filesystem library
To get the filesize (in bytes) of any file (test.xml in our example) using the boost::filesystem library, use this snippet:
filesize-example.cpp
#include <experimental/filesystem>
#include <iostream>
using namespace std;
using namespace std::experimental::filesystem;
int main() {
size_t filesize = file_size("test.xml");
cout << filesize << endl;
}You need to link the boost_filesystem and the boost_system libraries, i.e. compile like this:
build-filesize.sh
g++ -o test test.cpp -lboost_filesystem -lboost_systemCheck out similar posts by category:
C/C++
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow