# Saving and loading files

**URL:** <https://community.freefem.org/t/saving-and-loading-files/2121>\
**Category:** General Discussion\
**Created:** [November 16, 2022, 8:13pm UTC](https://community.freefem.org/t/saving-and-loading-files/2121 "2022-11-16T20:13:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![galfras](https://avatars.discourse-cdn.com/v4/letter/g/898d66/32.png) [@galfras](https://community.freefem.org/u/galfras)\
**Post date:** [November 16, 2022, 8:13pm UTC](https://community.freefem.org/t/saving-and-loading-files/2121/1 "2022-11-16T20:13:58Z")

</div>

Hello guys!

I need to save a solution and then read ir in another freefem file. I’m not sure how to do this. I am able to save the mesh and load it, but I can’t do dat with the solution.

Just to clarify:

```auto
problem Psiext(psiext,v)=
int2d(Sh)(-dx(psiext)*dx(v)-dy(psiext)*dy(v)-v*dx(psiext)/x)
-int2d(Sh)(-x*Jtor*v)
+on(izq,psiext=0)+on(circ,psiext=0); // condicion de Dirichlet de Soloviev

Psiext;

```

My solution would be psiext.

Thanks!

---

<div class="post-metadata">

**Author:** ![zhugp123](https://avatars.discourse-cdn.com/v4/letter/z/71e660/32.png) [@zhugp123](https://community.freefem.org/u/zhugp123)\
**Post date:** [November 18, 2022, 8:09am UTC](https://community.freefem.org/t/saving-and-loading-files/2121/2 "2022-11-18T08:09:31Z")

</div>

Maybe you can try **ifstream**

---

<div class="post-metadata">

**Author:** ![zhugp123](https://avatars.discourse-cdn.com/v4/letter/z/71e660/32.png) [@zhugp123](https://community.freefem.org/u/zhugp123)\
**Post date:** [November 19, 2022, 3:08pm UTC](https://community.freefem.org/t/saving-and-loading-files/2121/3 "2022-11-19T15:08:46Z")

</div>

using **ofstream** to save solutions and **ifstream** to load solutions.

---

<div class="post-metadata">

**Author:** ![galfras](https://avatars.discourse-cdn.com/v4/letter/g/898d66/32.png) [@galfras](https://community.freefem.org/u/galfras)\
**Post date:** [November 24, 2022, 4:34pm UTC](https://community.freefem.org/t/saving-and-loading-files/2121/4 "2022-11-24T16:34:44Z")

</div>

Hello! First of all, thank you for your anwser. I understand that ifstream and ofstream are the solution to my problem, but I have no idea which is the information I have to write down in the file. I am not sure if the solution is an 2D array of how the information is storaged.

---

<div class="post-metadata">

**Author:** ![agTSL](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@agTSL](https://community.freefem.org/u/agTSL)\
**Post date:** [November 25, 2022, 8:53am UTC](https://community.freefem.org/t/saving-and-loading-files/2121/5 "2022-11-25T08:53:52Z")

</div>

Hello,

You can try

```auto
/*
fespace Vh(Th, P1);
Vh Psiext;
*/
ofstream fileSol ("file.txt");
for (int i = 0; i<Vh.ndof; i++){
	fileSol <<psiext[][i]<<endl;
}

```

And do the same thing with ifstream to load your solution  
Alexandre
