# Input/output issues

**URL:** <https://community.freefem.org/t/input-output-issues/3996>\
**Category:** General Discussion\
**Created:** [July 7, 2025, 12:59pm UTC](https://community.freefem.org/t/input-output-issues/3996 "2025-07-07T12:59:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ipnglt](https://avatars.discourse-cdn.com/v4/letter/i/71e660/32.png) [@ipnglt](https://community.freefem.org/u/ipnglt)\
**Post date:** [July 7, 2025, 12:59pm UTC](https://community.freefem.org/t/input-output-issues/3996/1 "2025-07-07T12:59:21Z")

</div>

Dear all,

I am currently working on a code that computes the mean flow in a supersonic nozzle. To properly initialize each CFD run, I need to save and later read the simulation results. I chose to use `ifstream` and `ofstream` for this purpose. My problem is that I can write the solution to a file, but I can’t seem to read it back correctly.

To better isolate the problem, I created a simplified toy example (square geometry, no equation resolution, simple functions). Below is a minimal version of my code that reproduces the issue:

```auto
// Macro definition
macro defu(u) [u,u#y]//

// Mesh
mesh Th = square(50,50);

// FE space
fespace Xh(Th,[P2,P2]);
Xh defu(u) = [cos(0.5*pi*x),sin(0.5*pi*y)];

// Visualization
plot(Th,u,wait=1,fill=1);
plot(Th,uy,wait=1,fill=1);

// Saving
ofstream save("square.base");
save << u[] << endl;

// Reading
Xh defu(v);
ifstream read("square.base");
read >> v[];

```

It’s a fairly naive implementation, but I’m not sure what’s causing the problem. Any insights or suggestions would be greatly appreciated.

Best regards,

Ilyan

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [July 7, 2025, 5:09pm UTC](https://community.freefem.org/t/input-output-issues/3996/2 "2025-07-07T17:09:44Z")

</div>

I think you just forgot to use `{}` to properly scope your i/o streams.

---

<div class="post-metadata">

**Author:** ![ipnglt](https://avatars.discourse-cdn.com/v4/letter/i/71e660/32.png) [@ipnglt](https://community.freefem.org/u/ipnglt)\
**Post date:** [July 8, 2025, 3:44pm UTC](https://community.freefem.org/t/input-output-issues/3996/3 "2025-07-08T15:44:16Z")

</div>

Chris,

Thank you very much for your help — my code is working perfectly now.

Best,

Ilyan
