Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Hostgator 1 Penny

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


7,781 questions

10,865 answers

573 users

How to display (output) text file in hex using C++

1 Answer

0 votes
#include <iostream>
#include <fstream>
#include <iomanip>

using std::cout;
using std::endl;

#define SIZE 64

int main()
{
	std::ifstream ifs("d:\\data.bin", std::ios::in | std::ios::binary);

	if (!ifs) {
		cout << "Error open file" << endl;
		return 1;
	}

	char arr[SIZE];
	int i;

	cout.setf(std::ios::uppercase);
	while (!ifs.eof()) {
		for (i = 0; i < SIZE && !ifs.eof(); i++)
			ifs.get(arr[i]);
		for (int j = 0; j < i - 1; j++)
			cout << std::setw(3) << std::hex << (int)arr[j];

		cout << endl;
	}

	ifs.close();

	return 0;
}

/*
run:

2D  0  0  0  8  0  0  0  C  0  0  0 62  0  0  0 6B  3  0  0

*/

 




answered Jun 9 by avibootz
...