How to read entire text file into a buffer in C++

1 Answer

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

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

int main()
{
	unsigned char buf[1024] = { NULL };

	std::ifstream ifs("d:\\data.txt");

	ifs.read((char *)buf, sizeof buf);

	cout << buf << endl;

	ifs.close();

	return 0;
}

/*
run:

c c++
c# java php python

*/

 



answered Jun 9, 2018 by avibootz

Related questions

1 answer 270 views
1 answer 336 views
1 answer 316 views
1 answer 240 views
5 answers 462 views
1 answer 268 views
2 answers 259 views
...