-
Fstream limit?
Code:
int main()
{
BYTE Header[500];
fstream file_op("C:\\Test.exe",ios::in);
file_op.getline(Header,500);
for(int i = 0; i < 150; i++)
cout<<"\n"<<hex<<(int)Header[i];
return 0;
}
The first 118 bytes are correct, but all following bytes are 0xCC.
It reports bytes 115-120 are: 2E 0D 00 CC CC
The real bytes 115-120 are: 2E 0D 0D 0A 24
Is there a limit, or does anybody know what I'm screwing up?
-
Yes, you screwed up.
Open the file in binary mode.
-
getline() stops reading after it encounters '\n' or end of file, it does not alter contents of the remaining bytes in the buffer. The 0xcc that you see after the 118th byte was probably the way your compiler initialized the buffer. VC++ 6.0 will do that when the program is compiled in debug mode, I don't know buf I suspect VC++ .NET will too. If you don't want that behavior then initialize the buffer yourself
Code:
BYTE Header[500] = {0};