how to clear a file linux stack overflow

C++
truncate -s 0 filename

Source

Also in C++: