I'm at the time beginning the development of a simple hex editor(that only reads at the time). I want to substitute OA
for "\n"
, I'm trying with this code:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main() {
ifstream infile;
int crtchar = (int)infile.get();
infile.open("test.txt", ifstream::in);
while(infile.good())
{
if(crtchar != 0xA)
cout << hex << setfill('0') << setw(2) << crtchar << ":";
else
cout << endl;
}
cout << "\n=====================================\n";
infile.close();
return 0;
}
It compiles without errors, but when I try to execute it, I just got nothing:
C:\Documents and Settings\Nathan Campos\Desktop>hex
=====================================
C:\Documents and Settings\Nathan Campos\Desktop>
This is happening just after I've added the feature to substitute OA
for \n
, because before it w开发者_StackOverflowas working very nice. What is wrong?
You realize that you are only reading a character once, and before even opening the file, at that?
Sigh. You try to read the file before you open it.
Shouldn't you first open(...)
your file and then try to get()
from it?
Also, shouldn't you do more get()
's inside your while loop
Put int crtchar = (int)infile.get();
inside a while(infile.good())
and give it a try.
精彩评论