# From Cinder Asset to ifstream

**URL:** <https://discourse.libcinder.org/t/from-cinder-asset-to-ifstream/1475>\
**Category:** Uncategorized\
**Created:** [April 3, 2019, 11:16am UTC](https://discourse.libcinder.org/t/from-cinder-asset-to-ifstream/1475 "2019-04-03T11:16:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gazoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gazoo/32/61_2.png) [@Gazoo](https://discourse.libcinder.org/u/Gazoo)\
**Post date:** [April 3, 2019, 11:16am UTC](https://discourse.libcinder.org/t/from-cinder-asset-to-ifstream/1475/1 "2019-04-03T11:16:53Z")

</div>

Hey Embers,

The title more or less says it all. I’ve got a `vector<vector<float>>` that contains some data I need in order to simulate some behavior. I looked around ‘teh webz’ a bit and found this [helpful stackoverflow answer](https://stackoverflow.com/questions/15707537/how-to-save-vectorvectorvectorfloat-in-a-file-and-retrieve-data) that pointed me towards boost serialization.

The only problem is that I have no idea how (or even if it’s possible) to go from a `DataSource` to an `ifstream`. I tried putting together the following code instead

```
auto csvFileRef = ci::app::loadResource( RES_FFT_DATA );
auto csvDataString = ci::loadString( csvFileRef );
std::istringstream test( csvDataString );

boost::archive::binary_iarchive ia( test );
//boost::archive::binary_iarchive ia( in );
ia >> features;
//in.close();

```

But the `csvDataString` ends up only containing a single char, and then probably fails because the data isn’t actually originally a string.

Any ideas of how to pass the binary data from an asset into a format I can pipe into an `ifstream` would be much appreciated!

Cheers,

Gazoo

---

<div class="post-metadata">

**Author:** ![Gazoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gazoo/32/61_2.png) [@Gazoo](https://discourse.libcinder.org/u/Gazoo)\
**Post date:** [April 6, 2019, 4:00am UTC](https://discourse.libcinder.org/t/from-cinder-asset-to-ifstream/1475/2 "2019-04-06T04:00:35Z")

</div>

For those interested, I had some minor issues actually getting saving/loading a `vector<vector<float>>` to and from a file on disk, but I eventually got that sorted. Here’s the complete code which should work:

```
void SaveFeaturesFile( std::vector<std::vector<float>> const& features, std::string filename )
{
	std::ofstream out( filename.c_str(), std::ios::binary );
	boost::archive::binary_oarchive oa( out );
	oa << features;
	out.close();
}

void LoadFeaturesFileFromFile( std::vector<std::vector<float>> &features, std::string filename )
{
	std::ifstream in( filename.c_str(), std::ios::binary );
	boost::archive::binary_iarchive ia( in );
	ia >> features;
	in.close();
}

```

Note, this **is platform dependent** due to the data being stored in binary!

I also came across this [previous topic](https://discourse.libcinder.org/t/create-a-stringstream-from-cinder-buffer-avoiding-copying/153) which elaborates a bit on how to create `std::stringstream` from a cinder `buffer`, but I’ve yet to grasp how to work things out for binary data.

Cheers,  
Gazoo
