How to use unitbuf format flag to forcing flush to file after every insertion in C++

1 Answer

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

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

int main()
{
	std::ofstream file("d:\\test.txt");

	file << std::unitbuf << "C++ " << "Programming" << '\n'; // flush 3 times

	file.close();

	return 0;
}


/*
run:

test.txt:
---------
C++ Programming

*/

 



answered Apr 8, 2018 by avibootz

Related questions

1 answer 171 views
171 views asked Apr 7, 2018 by avibootz
1 answer 140 views
140 views asked Apr 7, 2018 by avibootz
1 answer 146 views
146 views asked Apr 7, 2018 by avibootz
1 answer 205 views
...