Why do I get different results reading a file in Unreal Engine vs Standalone?

I have been trying to read a .tif file using ifstream and I get incorrect data back when I run the code in Unreal Engine but when I read the same file using a standalone c++ program it reads the file correctly.

The data I read in UE:
Endian: i ￴ᆭ
Arbitrary Number: 4
IFD Address: 32763

The data I read standalone:
Endian: II
Arbitrary Number: 42
IFD Address: 192

I have confirmed the data read by the standalone c++ program is correct using notepad++ to view the files hex values. I don’t understand why I would get different results reading a file with the same code in Unreal vs standalone.

The code used to read the file:

short magicno;
char buffer[3];
int ifdaddress;

ifstream imfile;
imfile.open("ProjectPath/Content/file.tif", ios::binary);

imfile.seekg(0,ios::beg);

imfile.read(buffer,2);
imfile.read((char*)&magicno, 2);
imfile.read((char*)&ifdaddress, 4);

imfile.seekg(ifdaddress, ios::beg);

imfile.close();

cout<<"Endian: "<<buffer<<endl;
cout<<"Magic: "<<magicno<<endl;
cout<<"IFD Address: "<<ifdaddress<<endl;

You should check if the file was opened correctly. I think either of these work.

if (imfile)
{
  // File is open
}
else
{
  // Error
}

Or

if (imfile.is_open())
{
  // File is open
}
else
{
  // Error
}

edit:

If you want to get the file path of an asset, you can use the following code. Note that you’ll have to specifically add your file to your package if you intend to ship it. It’s in Project Settings->Project->Packaging. Then expand the Advanced section and add the folder to “Additional Non-Asset Directories to Package”.

	const FString AbsoluteGameContentDir = FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir());
	FString FileAbsolutePath = FPaths::ConvertRelativePathToFull(FPaths::Combine(AbsoluteGameContentDir, FilePathRelativeToContent));