The first two characters of any win32 exe are supposed to be MZ, so when I try to search for these characters using the following code it should output 0 (zero), but instead it outputs "characters not found".
When I try the same thing using a C code it gives the proper output i.e, zero.
Can someone please tell me whats wrong??
Code:#include<iostream> #include<fstream> int main() { std::fstream file("linked list.exe",std::ios::app|std::ios::binary); if(!file) { std::cout<<"unable to open"; } int i; char s[2]; for(i = 0;;i++) { file.seekg(i); file.read(s,2); if(s[0] == 'M' && s[1] == 'Z') { std::cout<<i; break; } if(file.eof()) { std::cout<<"Characters not found"; break; } } }