#include <fstream>
#include <iostream>
int main()
{
const char* fileName = "out1";
std::ofstream fs1(fileName);
fs1 << "AAAAAAAAAAA\n";
std::cout << fs1.tellp() << std::endl;
fs1.close();
std::ofstream fs2(fileName, std::ios_base::ate);
std::cout << fs2.tellp() << std::endl;
fs2.close();
return 0;
}
gcc 版本 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC)
g++ 文件02.cpp
./a.out
12 0
为什么 fs2.tellp() 打印 0 而不是 12?