The serialization library only reads what it wrote. So I would never expect to read the eof. And this is for a very good reason. It permits serialized data to be embedded inside of other data.
Robert Ramey
wrote in message news:810D860474553A4C884BBDA56703854DC05ACD0558@XEX.efs-us.com...
Hi,
I have checked some more on this and it seems there is one more character remaining after three objects has been read (0xa) and that is why eof() is not returning true. Can someone please let me know if they come across this problem or tell me what I am doing incorrect here? Thanks.
// File data that is being read
$ cat filename
22 serialization::archive 4 0 0 35 59 24.566999 14 Monday_Pointer 45 69 34.567001 15 Tuesday_Pointer 1 2 3.3 13 WEDNESDAY_PTR
// Y_PTR = Y= 59 _ = 5f, P = 50, T = 54, R = 52
// 5f59 5450 0a52
$ od -x filename
0000000 3232 7320 7265 6169 696c 617a 6974 6e6f
0000020 3a3a 7261 6863 7669 2065 2034 2030 2030
0000040 3533 3520 2039 3432 352e 3636 3939 2039
0000060 3431 4d20 6e6f 6164 5f79 6f50 6e69 6574
0000100 2072 3534 3620 2039 3433 352e 3736 3030
0000120 2031 3531 5420 6575 6473 7961 505f 696f
0000140 746e 7265 3120 3220 3320 332e 3120 2033
0000160 4557 4e44 5345 4144 5f59 5450 0a52
0000176
Follows is updated program:
while (!ifs.eof()) {
std::cout << "BAD: " << (ifs.rdstate() & std::ios::badbit)
<< "FAIL:" << (ifs.rdstate() & std::ios::failbit)
<< "GOOD: " << (ifs.rdstate() & std::ios::goodbit)
<< "EOF: " << (ifs.rdstate() & std::ios::eofbit)
<< std::endl;
std::cout << " ++++++++++++++++ " << std::endl;
if (counter == 3) {
while (!ifs.eof()) {
std::cout << ifs.get() << std::endl;
}
std::cout << "BAD: " << (ifs.rdstate() & std::ios::badbit)
<< "FAIL:" << (ifs.rdstate() & std::ios::failbit)
<< "GOOD: " << (ifs.rdstate() & std::ios::goodbit)
<< "EOF: " << (ifs.rdstate() & std::ios::eofbit)
<< std::endl;
break;
}
++counter;
ia >> g;
std::cout << g.degrees << " : "
<< g.minutes << " : "
<< g.seconds << " : "
<< g.day <
#include
#include
#include
#include
/////////////////////////////////////////////////////////////
// gps coordinate
//
// illustrates serialization for a simple type
//
class gps_position
{
private:
friend class boost::serialization::access;
// When the class Archive corresponds to an output archive, the
// & operator is defined similar to <<. Likewise, when the class Archive
// is a type of input archive the & operator is defined similar to >>.
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & degrees;
ar & minutes;
ar & seconds;
ar & day;
}
public:
int degrees;
int minutes;
float seconds;
std::string day;
gps_position(){};
gps_position(int d, int m, float s, std::string inDay) :
degrees(d), minutes(m), seconds(s), day(inDay)
{}
};
int main() {
// create and open a character archive for output
std::ofstream ofs("filename");
// create class instance
const gps_position g(35, 59, 24.567f, "Monday_Pointer");
const gps_position g1(45, 69, 34.567f, "Tuesday_Pointer");
const gps_position * g2 = new gps_position(1,2,3.3, "WEDNESDAY_PTR");
{
boost::archive::text_oarchive oa(ofs);
oa << g;
oa << g1;
oa << (*g2);
}
{
/**gps_position g;
std::vector vec;
std::ifstream ifs("filename");
boost::archive::text_iarchive ia(ifs);
while (!ifs.eof()) {
std::cout << " ++++++++++++++++ " << std::endl;
ia >> g;
std::cout << g.degrees << " : "
<< g.minutes << " : "
<< g.seconds << " : "
<< g.day < gps;
std::ifstream ifs("filename");
boost::archive::text_iarchive ia(ifs);
ia >> gps;
for (int i = 0; i < gps.size(); ++i) {
std::cout << gps[i].degrees << " : "
<< gps[i].minutes << " : "
<< gps[i].seconds << " : "
<< gps[i].day <http://lists.boost.org/mailman/listinfo.cgi/boost-users