1

a の内容をvector<vector<vector<float> > >ファイルに保存してから、正しい位置にあるすべての値を取得する必要があります。

提案?

4

4 に答える 4

2

ブーストシリアル化ライブラリをご覧ください。

于 2013-03-29T16:47:46.007 に答える
2

自分でやりたい場合は、次のようにすることができます。

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を実行します。

于 2013-03-29T17:11:21.570 に答える
1

バイト単位でバイナリファイルに書き出すことができます。次に、それを読み戻すと、それを char 配列に読み込んで、型にキャストできます。

http://courses.cs.vt.edu/cs2604/fall02/binio.htmlをご覧ください

于 2013-03-29T16:45:54.300 に答える
0

解決しました、ありがとう

#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

于 2013-03-29T18:32:58.430 に答える