Reputation: 435
I am writing a c++ program to write to a text file of a specified size. I initially create a text file of size specified say 2 KB, I want to keep writing to this file till the 2 KB limit is reached and that point notify the user. I am not sure what the best way is. I am looking for a cross platform solution. Would something like libevent (http://libevent.org/) be good for this or am I missing something simpler.
Any advice/help greatly appreciated.
Thanks
Upvotes: 0
Views: 925
Reputation: 393674
#include <fstream>
int main()
{
std::ofstream ofs("output.img", std::ios::binary | std::ios::out);
ofs.seekp((2<<10) - 1);
ofs.write("", 1);
}
std::ofstream::tellp()
stat
will be able to get up-to-date filesize without re-opening the fileUpvotes: 4