# Closing an output file steam - does it need to be flushed?

**URL:** https://community.freefem.org/t/closing-an-output-file-steam-does-it-need-to-be-flushed/2413
**Category:** General Discussion
**Created:** [April 22, 2023, 10:51am UTC](https://community.freefem.org/t/closing-an-output-file-steam-does-it-need-to-be-flushed/2413 "2023-04-22T10:51:41Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)
#### Post date: [April 22, 2023, 10:51am UTC](https://community.freefem.org/t/closing-an-output-file-steam-does-it-need-to-be-flushed/2413/1 "2023-04-22T10:51:41Z")

</div>

I was using this macro without the flush but the last value in the last line was missing  
sometimes. On a quick check, adding the flush may have fixed it.  
This looks like a problem with the ofstream flushing when destoryed  
on going out of scope. Is there a close or something to use?

```auto
// possible bug/ feature - last element of last dropped
// sometimes with the ofs.flush
macro mmsave(fn,u,Xh)
{
try{
ofstream ofs(fn);
Xh xx=x;
Xh yy=y;
int n=u[].n;
for(int i=0; i<n; ++i)
{ ofs<<xx[][i]<<" "<<yy[][i]<<" "<<u[][i]<<endl; ofs.flush; }
} catch (...) { cout<<" throw during save to "<<fn<<endl; cout.flush; }
} // EOM
                                                                    30,1 80%

```
