【发布时间】:2019-11-17 19:55:10
【问题描述】:
我在驱动器 C: 上有 430 GB 可用空间。但是对于这个程序:
#include <iostream>
#include <boost/filesystem.hpp>
int main()
{
boost::filesystem::path p("C:");
std::size_t freeSpace = boost::filesystem::space(p).free;
std::cout<<freeSpace << " Bytes" <<std::endl;
std::cout<<freeSpace / (1 << 20) << " MB"<<std::endl;
std::size_t availableSpace = boost::filesystem::space(p).available;
std::cout << availableSpace << " Bytes" <<std::endl;
std::cout << availableSpace / (1 << 20) << " MB"<<std::endl;
std::size_t totalSpace = boost::filesystem::space(p).capacity;
std::cout << totalSpace << " Bytes" <<std::endl;
std::cout << totalSpace / (1 << 20) << " MB"<<std::endl;
return 0;
}
输出是:
2542768128 Bytes
2424 MB
2542768128 Bytes
2424 MB
2830102528 Bytes
2698 MB
我需要知道有多少可用磁盘空间,因为我的应用程序必须下载一个巨大的文件,并且我需要知道下载它是否可行。
我在 Windows 上使用 mingw:
g++ (i686-posix-dwarf-rev2, Built by MinGW-W64 project) 7.1.0
我还尝试使用 MXE 从 Linux 交叉编译:
i686-w64-mingw32.static-g++ (GCC) 5.5.0
两者都返回相同的数字。
【问题讨论】:
标签: c++ windows boost diskspace boost-filesystem