c++ – Run-Time Check Failure #2 – Stack around the variable ‘x’ was corrupted


When I run this code, it shows an output but then there is an error:


#include <iostream>
#include <fstream>
#include <windows.h>

using namespace std;

int main()
{
    ifstream image;
    image.open("C:/Users/user/Desktop/datasets/300/Cheque 083655.tif", std::ios_base::binary);

    if (image.is_open())
    {
        cout << "Successn";
    }

    else
    {
        cout << "Cannot open file n";
    }

    image.seekg(1, ios::beg);

    char x;

    image.read((&x), 2);

    cout << static_cast<int>(x) << endl;

    image.close();

    system("pause");

}

Output:

Success
73

Error:

Run-Time Check Failure #2 - Stack around the variable 'x' was corrupted.

I’ve read the same question, but I still can’t fix this error, can anybody tell me how to fix it?