# How to read and write a data structure in a flat file?.

**URL:** <https://forums.unrealengine.com/t/how-to-read-and-write-a-data-structure-in-a-flat-file/739471>\
**Category:** C++\
**Tags:** unreal-engine, CPP, question\
**Created:** [December 31, 2022, 5:00pm UTC](https://forums.unrealengine.com/t/how-to-read-and-write-a-data-structure-in-a-flat-file/739471 "2022-12-31T17:00:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [December 31, 2022, 5:00pm UTC](https://forums.unrealengine.com/t/how-to-read-and-write-a-data-structure-in-a-flat-file/739471/1 "2022-12-31T17:00:59Z")

</div>

I want to make a small code to select my development credentials for EOS. Because it’s a headache not to do this automatically.

So all I need is to know how to read and write a data structure to a file.

Basically what I want to do is this:  
Something extremely simple that would make everything much easier.

 ![1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/5/9/a59c39b3db637048c9ea000dc46038cbd638472f.png)  
 ![2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/f/2/2f2e658d0e2f3b18658abb7c87c58ac0e4aa7f24.png)  
 ![3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/8/b/e8b95eed473cc6d7401949ed69fda661d5310b6b.png)

The problem is that I’ve been reading the documentation and various posts on this forum and I can’t find any function or library that allows me to read and write a data structure in a file.

For example:  
[https://docs.unrealengine.com/4.27/en-US/API/Runtime/Core/Misc/FFileHelper/](https://docs.unrealengine.com/4.27/en-US/API/Runtime/Core/Misc/FFileHelper/)

Or

> **[File manipulation: Read,Write | Unreal Engine Community Wiki](https://unrealcommunity.wiki/file-manipulation:-readwrite-5nytg2tu)**
>
> Introduction In this article, I will show you how to Read Manipulate and write to a file. We will be focusing on the content of a file. If you want to do something like to Create, find, Copy, Or De...

or

> **[Unreal Engine C++ Save System (SaveGame)](https://www.tomlooman.com/unreal-engine-cpp-save-system/)**
>
> UE4 SaveGame system to save player data and world state to disk. Including all source coded needed to get started.

or

> [@Read and Write data from text file](https://forums.unrealengine.com/t/read-and-write-data-from-text-file/291916):
>
> Is it possible to read and write data from a text file for example use the text files data ( exampletext ) and store it as a variable Player-\>Name = file; out put = hello, exampletext if that is understandable confused

Is there any way to do this?

Thank you very much!!

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [December 31, 2022, 6:21pm UTC](https://forums.unrealengine.com/t/how-to-read-and-write-a-data-structure-in-a-flat-file/739471/2 "2022-12-31T18:21:08Z")

</div>

Hi Ivan3z,

Just make “ToString” and “FromString” functions in your structure and save using something like the FPlatformFileManager.

Those are just wrappers to allow file IO on all platforms - if you’re just using windows or another OS you can of course just write your own routines using that platforms IO routines (eg iostream).

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [December 31, 2022, 6:47pm UTC](https://forums.unrealengine.com/t/how-to-read-and-write-a-data-structure-in-a-flat-file/739471/3 "2022-12-31T18:47:59Z")

</div>

Hi  
That’s great to be able to use standard C++.  
I thought that could cause problems.  
This has happened to me using some libraries.

The code is just to help while I program the epic online services.  
After that the code will not be necessary.  
So I think the wrapper will not be necessary in this case.

Thank you very much for your help!!  
Now I know what to do next time I have a similar problem!!  
Very appreciated!! ❤
