Я пытаюсь читать и писать в шестнадцатеричном формате, но у меня возникают проблемы с вводом шестнадцатеричного кода и чтением шестнадцатеричного гексагона обратно как hex, а не ascii. Что заставляет меня печатать адреса и значения правильно, я не совсем уверен, что я делаю это правильно. какие-либо намеки на то, что я делаю неправильно? Хорошо, теперь он работает только для того, чтобы исправить чтение, чтобы напечатать фактический адрес вместо введенного адреса + 1.
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
int main(int argc,char ** argv) {
if(argc <= 1) {
cout<<"Enter a file name please";
exit(0);
} else {
fstream in;
in.open(argv[1],fstream::in | fstream::out | fstream::binary);
string input;
unsigned int v;
unsigned int print;
unsigned int g;
int iter;
for(iter = 0; input!="save";){
cout<<"Hex Edit("<<argv[1]<<"): ";
cin>>input;
if(input == "read"){
cout<<"Enter Offset: ";
cin>>hex>>v;
in.seekg(v);
print=in.get();
g=in.tellg();
cout<<"Value at offset("<<hex<<g<<"): "<<hex<<print;
cout<<endl;
}
if(input == "write"){
cout<<"Enter Offset: ";
cin>>hex>>v;
in.seekp(v);
cout<<"Enter Value: ";
cin>>hex>>v;
in.put(v);
}
} else if(input == "save") {
in.close();
}
cout<<endl;
}
}
return 0;
}