我想知道C ++中文件的文件大小而不使用某些非标准的_64 (f)stat thingy。根据{{3}},答案应该是
xs=[0.041984,0.374045,0.625954,0.874045,1.374045,1.870229,2.362595,2.862595,3.358778,3.854961,4.354961,5.354961,7.343511,8.835877,9.335877,10.33587]
ys=[14.145,14.235,14.275,14.24,13.91,13.7,13.57,13.52,13.55,13.56,13.45,13.44,13.46,13.44,13.45,13.45]
f = interp1d(xs,ys,"cubic")
但我在VS 2013 Update5中的64位示例显示了一个奇怪的行为: 如果文件小于4G,则上述解决方案有效,否则返回-1。
using namespace std;
ifstream::pos_type filesize(const char* filename)
{
ifstream in(filename, ifstream::ate | ifstream::binary);
return in.tellg();
}
以下代码适用于所有情况。
ofstream myfileo("example.bin", ios::binary); // create an example file
auto pos = (4ULL * 1024 * 1024 * 1024); // 4 Gigs
myfileo.seekp(pos);
myfileo << "This is a line.\n";
myfileo.close();
ifstream myfile("example.bin", ios::binary | ios::ate); // get filesize V1
auto len = myfile.tellg();
myfile.close();
cout << "size is: " << len << " bytes.\n"; // only works if file < 4G
那么,这只是一个MS问题还是我错过了什么?