I am writting a function for my code.
the function only need a opened file to process.
here the code of the function :
void printFile(std::ifstream &file)
{
file.seekg(0, file.end);
int length = file.tellg();
file.seekg(0, file.beg);
char *buffer = new char[length];
file.get(buffer, length);
file.seekg(0, file.beg);
char c;
int i = 0;
std::cout << "Uncreypted file" << std::endl;
while (file.get(c))
{
// loop getting single characters
std::cout << c << " " << buffer[i] << " ";
i++;
}
std::cout << std::endl;
delete[] buffer;
}
the result is weird :
Uncrypted file
t h h i i s s i i s s a a t t e e s s t t
t ═ h ═ i ═ s ═ ═ i ═ s ═ ═ a ═ ═ l ═ i ═ g ═ n ═
after one line the buffer output something different where as file.get.(c)
work proprely, why ?
Is this because of the carriage return ascii letter
?