How to re-opening closed text files 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 << ifs.gcount() << endl;
	ifs.close();
	ifs.clear();

	ifs.open("d:\\data.txt");
	ifs.read((char *)buf, sizeof buf);
	cout << ifs.gcount() << endl;
	ifs.close();

	return 0;
}

/*
run:

25
25

*/

 



answered Jun 10, 2018 by avibootz

Related questions

...