【问题标题】:What is the most efficient way to read from the end of a file in c++? (Parsing last 128 bits in a file)在 C++ 中从文件末尾读取的最有效方法是什么? (解析文件中的最后 128 位)
【发布时间】:2012-03-10 17:16:06
【问题描述】:

我能想到几种快速读取最后 128 位的方法,但哪种方法最简单、最有效?

【问题讨论】:

  • 将文件指针移动到EOF-16并读取直到EOF
  • 我还没有写任何东西,但我要做的是读取文件大小,然后寻找文件大小 - 128。虽然这似乎不是最优雅的解决方案。
  • @juergen d 哈哈猜这是一个好的解决方案。

标签: c++ file-io bits id3


【解决方案1】:

跳到最后阅读:

char buf[16];

std::ifstream infile("thefile.bin", std::ios::binary);
infile.seekg(16, std::ios::end);

if (!infile || !infile.read(buf, 16))
{
    // error! Maybe die.
}

// process buf

【讨论】:

  • @user979663:因为在大多数架构上 128 位是 16 字节。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-03-27
  • 2013-03-23
  • 1970-01-01
  • 2013-07-06
  • 2017-02-11
  • 2012-05-28
  • 1970-01-01
相关资源
最近更新 更多