|
안녕하세요.
문제가 생길때마다 매번 여기와서 해결을 했는데........... 이번에도...... ^^;;
다음 아래와 같이 벡터들을 생성 했는데 이 벡터들을 바이너리 파일에 쓰는 방법에 있어 아직 지식이 짧아 질문 드립니다.
아래 코드에 보면 vector< vector<int>> variable_node, check_node 로 두개의 바이너리 벡터를 생성했는데 이 variable_node 와 check_node 벡터를 벡터의 특성을 그대로 유지하며 바이너리 파일로 저장을 해야하는데 어떻게 해야할지 몰라서요.
고수님들의 조언을 부탁드립니다.
꾸벅.
==================================================================================
#예제코드
#ifdef __BORLANDC__
#pragma argsused
#endif
#include <iostream> //<---For 'cin' and 'cout'
#include <fstream> //<---To open a file stream
#include <vector> //<---Check this by yourself why..
#include <algorithm> //<---To call methods 'random_shuffle',
using namespace std;
int main(int argc, char* argv[])
{//<---Begin of main()
char* OutputFileName;//<--- The binary file name to which binary vectors are stored.
//OutputFileName=argv[1]
if(!argv[2])
{OutputFileName="test.bin";}//<---Default binary Output File Name.
else
{OutputFileName=argv[1];}
vector< vector<int> > variable_node;
vector<int> vn_temp;
int N=1000;
int N_i;
for(int i=0; i<N;i++)
{
N_i=(10 + (7*i))%10;
for(int j=0; j<N_i; j++)
{
vn_temp.push_back(1+(i%10));
}
variable_node.push_back(vn_temp);
vn_temp.clear();
}
vector< vector<int> > check_node;
vector<int> cn_temp;
int M=500;
int M_i;
for(int i=0; i<M ;i++)
{
M_i=(5 + (7*i))%5;
for(int j=0; j<M_i; j++)
{
cn_temp.push_back(1+(i%10));
}
variable_node.push_back(cn_temp);
cn_temp.clear();
}
ofstream LdpcSparse(OutputFileName, ios::out&& ios::binary);//<-- Output file stream.
/*
여기까지가 variable_node 와 check_node를 생성하는 예제였습니다.
이제 제가 해야될일은 위에서 생성된 variable_node와 check_node가
vector< vector<int> >로 정의된 벡터구조를 그대로 가지면서
OutputFileName이란 이름으로 binary 파일로 저장해야 하는데 어떻게 해야할지 모르겠습니다.
인터넷에서 자료를 찾아 이리저리 뒤지고 있지만 쉬이 나오지 않네요.
string의 경우 "<<" operator 로 쉽게 저장이 되던데...
벡터의 경우 위에서 정의된 Output file stream 인 LdpcSparse를 다음과 같이 사용할수 있는
방법 없을까요? 이렇게요
LdpcSparse << variable_node;
LdpcSparse << check_node;
마치 스트림을 다루던것처럼요.
많은 조언 부탁드립니다.
꾸벅..
추신: 으흑....operator의 길은 멀고도 험하구나...
*/
}//<---End of main()
|