在C++中,你可以使用std::ifstream类来读取文件内容,并使用std::stringstream类将文件内容解析为16进制数字。下面是一个示例代码:

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>

int main() {
    std::string filePath = 'D:/workspace_zq/VDR材料/D230316_1131_xH85E93.VDR';
    std::ifstream file(filePath, std::ios::binary);

    if (file) {
        std::stringstream buffer;
        buffer << file.rdbuf();

        std::string hexString = buffer.str();
        // 这里的hexString就是文件内容的16进制表示

        // 输出16进制字符串
        std::cout << hexString << std::endl;

        file.close();
    } else {
        std::cerr << "Failed to open file: " << filePath << std::endl;
    }

    return 0;
}

注意,上述代码假设文件内容是一个有效的16进制字符串。如果文件内容不是有效的16进制字符串,你可能需要进行额外的解析和处理。

C++ 读取文件内容并解析为16进制数字

原文地址: https://www.cveoy.top/t/topic/fK6g 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录