我需要使用 Qt 工具将文件读取为二进制代码。在标准 C++ 中,我是这样做的:
#include <iostream>
#include <vector>
#include <fstream>
int main() {
std::ifstream file("C:\\Users\\%username%\\Desktop\\programme.exe",
std::ios::binary);
std::vector<char> vec((std::istreambuf_iterator<char>(file)),
(std::istreambuf_iterator<char>())); // that variable has the binary code
file.close();
return 0;
}
最佳答案
Qt 是使用标准 C++ 以及根据操作系统和体系结构使用 native 调用编写的。因此,正常的 c++ 文件 I/O 仍然有效并且是可移植的,否则请查看 QFile 文档 here .你会想看看提到 QDataStream
关于c++ - 如何在 Qt 中将文件读取为二进制代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46737785/