c++ 加载资源文件的字节
以下是C++中加载资源文件的字节的示例代码:
#include <iostream>
#include <fstream>
#include <vector>
int main() {
// 读取资源文件
std::ifstream file("resource.txt", std::ios::binary);
// 判断文件是否打开成功
if (!file.is_open()) {
std::cerr << "Failed to open file" << std::endl;
return 1;
}
// 读取文件字节到vector中
std::vector<char> bytes((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
// 打印每个字节的十六进制值
for (char byte : bytes) {
std::cout << std::hex << static_cast<int>(byte) << " ";
}
std::cout << std::endl;
return 0;
}
在上面的代码中,我们首先打开文件,然后通过std::vector将文件的字节读取到内存中。最后,我们循环遍历字节并打印它们的十六进制值。
原文地址: https://www.cveoy.top/t/topic/NpA 著作权归作者所有。请勿转载和采集!