Bugfix: std::ofstream fout scope issue: may cause Segfault on linux.