a の内容をvector<vector<vector<float> > >
ファイルに保存してから、正しい位置にあるすべての値を取得する必要があります。
提案?
ブーストシリアル化ライブラリをご覧ください。
自分でやりたい場合は、次のようにすることができます。
std::ofstream file("floats.bin", std::ios::binary);
std::vector<float> f;
std::size_t n = f.size();
// save the size of the vector so you know how much to read
// when you load from file
file.write( reinterpret_cast<char*>( &n ), sizeof(n) );
// write the data
file.write( reinterpret_cast<char*>( f.data() ), sizeof(float) * n );
すべての内部ベクトルに対してこれを行う必要があります。ファイル形式の正確な詳細を決定するのはあなた次第です。ただし、さまざまなサイズのデータ型を考慮してください。
データを読み戻すには、まずサイズ情報を読み取り、それに応じてベクトルのサイズを変更してから、ifstream::readを実行します。
バイト単位でバイナリファイルに書き出すことができます。次に、それを読み戻すと、それを char 配列に読み込んで、型にキャストできます。
解決しました、ありがとう
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/list.hpp>
void saveFeaturesFile(vector<vector<vector<float> > > &features, string filename){
ofstream out(filename.c_str());
stringstream ss;
boost::archive::binary_oarchive oa(ss);
oa << features;
out << ss.str();
out.close();
}
void loadFeaturesFile(vector<vector<vector<float> > > &features, string filename){
ifstream in(filename.c_str());
boost::archive::binary_iarchive ia(in);
ia >> features;
in.close();
}
およびリンクされた -lboost_iostreams -lboost_serialization