I try to write a program used to Compressed file, but I get different output everytime I run the program. when I debug this program, I find that std::ifstream will get different results between Release and Debug. And this is my program:
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream inputfile("testing_file.txt");
inputfile.seekg(0, ios::end);
unsigned long filesize = inputfile.tellg();
inputfile.seekg(0, ios::beg);
char* buffer = new char[filesize];
inputfile.read(buffer, filesize);
for (int i = 0; i < filesize; ++i) {
cout << (int)*(buffer + i) << endl;
}
delete[] buffer;
inputfile.close();
cin.get();
return 0;
}
this is the testing_file.txt :
for test !
I get this when using Release mode :
102
111
114
32
116
101
115
116
32
33
10
0
but I get this in Debug mode :
102
111
114
32
116
101
115
116
32
33
10
-51
so I went to ask why I will get two different output in the same program.
sorry for my bad English.