如何使用 boost::filesystem 库获取文件大小
要使用 boost::filesystem 库获取任何文件(在我们的示例中为 test.xml)的文件大小(以字节为单位),使用此代码片段:
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;
}你需要链接 boost_filesystem 和 boost_system 库,即像这样编译:
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