|
-
January 24th, 2016, 11:50 PM
#1
How to use C++ Boots installation and map serialization?
Friends I tried to store map data into file this way but not able to use it.
I read many pages from boots help but it is not clear to me so if you know any link which is showing step by step information about how to use boots kindly post here.
First of all installing boots is very hard.
I done following for boost installation:
1. Download boost zip and unzip
2. Set path for gcc
3. Run Bootstrap.bat gcc
4. Run B2.exe toolset=gcc
5. Add boots folder in CodeBlocks Settings Compiler Search directories Compiler tabs
Q.1. Do I need to anything else to install and run boost?
Q.2. How I can write and read map in to file?
I got this error:
C:\boost_1_60_0\boost\serialization\access.hpp|116|error: 'class Account' has no member named 'serialize'|
Here is my dummy code.
Code:
// This is dummy code
// Account.h is something like this
#include <iostream>
#include <iomanip>
using namespace std;
class Account
{
private:
static int lastAcNo;
static float sbRate;
string name;
string acType;
public:
Account()
{
}
void create(string s)
{
}
void print()
{
}
};
// Bank.h something like this
#include <iostream>
#include <fstream>
#include <map>
#include "Account.h"
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
using namespace std;
int Account::lastAcNo = 0;
float Account::sbRate = 0;
class Bank
{
private:
typedef map<int, Account> bankMap;
bankMap data;
string bankName;
int lastAcNo;
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & data;
}
void writeAccountData()
{
// here i want to write entire map to file or just a object whichever is easy
// but i don't know steps for using boots
Account ac;
ofstream dataFile;
dataFile.open("BankData.dat", ios::out|ios::binary);
boost::archive::text_oarchive bDataFile(dataFile);
cout << endl << "Writing data..." << endl;
for(bankMap::iterator i = data.begin(); i != data.end(); ++i)
{
ac = i->second;
bDataFile << ac;
//first i used normal storing but it is also not working
//dataFile.write(reinterpret_cast<char *>(&ac), sizeof(ac));
}
dataFile.close();
cout << endl << "Finish writing." << endl;
}
void readAccountData()
{
// here i want to read entire map or object
fstream dataFile;
dataFile.open("BankData.dat",ios::in|ios::binary);
boost::archive::text_iarchive bDataFile(dataFile);
cout << endl << "Reading data..." << endl;
if(dataFile.fail())
{
Account::setLastAcNo(101);
return;
}
else
{
Account ac;
dataFile.seekg(0,ios::end);
int size = dataFile.tellg();
int totAc = size/sizeof(ac);
dataFile.seekg(0,ios::beg);
int tAcNo;
for(int i=0; i<totAc; i++)
{
//first tried to read like this but not working
//dataFile.read(reinterpret_cast<char *>(&ac), sizeof(ac));
bDataFile >> ac;
data.insert(make_pair(ac.getAcNo(),ac));
tAcNo = ac.getAcNo();
}
Account::setLastAcNo(++tAcNo);
cout << endl << "Finish reading." << endl;
}
dataFile.close();
}
public:
Bank()
{
readAccountData();
}
~Bank()
{
writeAccountData();
}
}
//main.cpp file something like this
int main()
{
Bank b;
b.menu();
return 0;
}
Last edited by P_N_Data_System; January 25th, 2016 at 06:23 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|