Initial data: There is a binary file which we read ifstream in (FName, ifstream::binary); . There is a structure containing char type fields. char a[8]; It is necessary to read the file into the structure and output hex ;. Do so
ifstream in (FName, ifstream::binary); in.read((char*)&X, sizeof X); //效懈褌邪械屑 褋褌褉褍泻褌褍褉褍 int len1=in.gcount(); ofstream fout(FName1); fout << "袩芯谢械="; for(int i = 0; i <= 7; i++) { fout<<setfill ('0')<<setw(2)<<hex<<(int)Xa[i]; }; When outputting in the byte, there appears an extra ffffff.
Question: How to get rid of extra characters?