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 read complete binary file in buffer with C++

2 Answers

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

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

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

	if (file.is_open()) {
		int pos = file.tellg();
		char *buf = new char[pos + 1];
		file.seekg(0, std::ios::beg);
		file.read(buf, pos);
		file.close();

		buf[pos] = NULL;

		cout << buf << endl;

		delete[] buf;
	}
	else
		cout << "Error open file" << endl;

	return 0;
}


/*
run:

├⌡H@∞╤»BתשM┴

*/

 




answered Jun 7 by avibootz
edited Jun 7 by avibootz
0 votes
#include <iostream>
#include <fstream>
#include <vector>

using std::cout;
using std::endl;
using std::ifstream;
using std::vector;

int main()
{
	ifstream file("d:\\data.bin", std::ios::binary | std::ios::ate);
	std::streamsize size = file.tellg();
	file.seekg(0, std::ios::beg);

	vector<char> buffer(size);
	if (file.read(buffer.data(), size)) {
		for (char ch : buffer)
			cout << ch << " ";
	}

	return 0;
}


/*
run:

├ ⌡ H @ ∞ ╤ » B ת ש M ┴ 

*/

 




answered Jun 7 by avibootz
...