Check out example codes for "clear file before writing c++". It will help you in understanding the concepts better.

Code Example 1

std::ofstream ofs;
ofs.open("test.txt", std::ofstream::out | std::ofstream::trunc);
ofs.close();

Learn ReactJs, React Native from akashmittal.com