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 253 views
1 answer 303 views
1 answer 291 views
1 answer 226 views
5 answers 432 views
1 answer 251 views
1 answer 233 views
...