我已经阅读了很多关于在 C++ 中不使用 C 风格的内容,而是使用 std::array、std::vector 或 std::string 等容器。
现在我正在尝试使用文件流读写小型二进制文件并将其存储在 std::array 中。
看起来 std::fstream 中的 read 和 write 方法只能用于 C 样式的数组...
所以这就是我的想法:
int main(int argc, char **argv)
{
std::fstream testFile, outTestFile;
testFile.open("D:/mc_svr/another/t/world/region/r.0.0.mca", std::fstream::in | std::fstream::binary);
outTestFile.open("D:/mc_svr/another/t/world/region/xyz.xyz", std::fstream::out | std::fstream::binary);
std::array<byte_t, 8192> testArray;
testFile.read((char*) &testArray, 8192);
outTestFile.write((char*) &testArray, 8192);
testFile.close();
outTestFile.close();
return 0;
}
byte_t 只是一个
typedef char byte_t;
有用。但这是做到这一点的好方法吗?如果没有,还有什么其他方法可以做到这一点?我应该改用 byte_t [] 吗?