如果十六进制值为 34,请将其更改为 32,如果是 2B,请将其更改为 2C

问题描述 投票:0回答:1

过去 5 天我一直在尝试找出如何让我的程序显示十六进制值是否为 34,然后将其更改为 32:

如果值为 2C,则将其更改为 2B:

到目前为止,我已经搞乱了这段代码:

#include <fstream>
#include <iostream>
    
int main()
{
    int value;
    
    if (value > 0x34)
    {
        std::fstream binaryFile("test.tex", std::ios::in | std::ios::out | std::ios::binary);
        binaryFile.seekp(0x18/*offsetToWrite*/);
        binaryFile << char(0x32/*ValueToReplace*/);  
    } 
    else if (value < 0x2C) {
        std::fstream binaryFile("test.tex", std::ios::in | std::ios::out | std::ios::binary);
        binaryFile.seekp(0x18/*offsetToWrite*/);
        binaryFile << char(0x2B/*ValueToReplace*/);  
    }
}

我尝试使用

if
else if
语句,但它们不起作用。

c++ if-statement hex
1个回答
0
投票

您的

value
变量是未初始化。您需要打开文件,查找到所需的位置,从文件中读取值,然后比较该值,如果需要,则返回到该位置并将新值写入该值。

© www.soinside.com 2019 - 2024. All rights reserved.