如何使用 C++17 的 std::filesystem 获取 C++ 文件大小
最近版本的 C++ 具有内置的跨平台文件系统库,支持许多有用的操作如获取文件大小。
filesize_example.cpp
#include <filesystem>
// 使用示例:
std::filesystem::file_size("myfile.bin");完整示例:
filesize_full.cpp
#include <filesystem>
#include <iostream>
int main() {
std::uintmax_t filesize = std::filesystem::file_size("myfile.bin");
std::cout << "Filesize in bytes is " << filesize << std::endl;
return 0;
}Check 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