c++ - 如何在 Qt 中将文件读取为二进制代码?

标签 c++

我需要使用 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/

相关文章:

c++ - 通过按下 Qt 中的按钮来启用 bool 变量

c++ - C++返回字符数组相减的结果

c++ - 基本 C++ 递归

c++ - 在 C++ 中包含 C 代码

c++ - OpenGL 统一函数 - 为什么这么多?

c++ - clang-tidy 报告未知警告

c++ - QFile "remove()"不删除执行时众所周知的文件

c++ - 编写模板

android - Qt 检查平台类型 : Mobile or Desktop

c++ - 如何在 C++ 中表达 Delphi 运算符 "<>"?