Beginning to 编程

VC++ 方面编程文章

 

boost serialize 和 ostream 问题

下面是Boost serialization 中的demo例子
为何写了serialize 函数还写个ostream<<
阿,
我对ostream 不是很了解,
我的印象是iostream 是在控制台里输入输出的
/////////////////////////////////////////////////////////////////////////////
class gps_position
{
    friend std::ostream & operator<<(std::ostream &os, const gps_position &gp);
    friend class boost::serialization::access;
    int degrees;
    int minutes;
    float seconds;
    template<class Archive>
    void serialize(Archive & ar, const unsigned int /* file_version */){
        ar & degrees & minutes & seconds;
    }
public:
    // every serializable class needs a constructor
    gps_position(){};
    gps_position(int _d, int _m, float _s) :
        degrees(_d), minutes(_m), seconds(_s)
    {}
};
std::ostream & operator<<(std::ostream &os, const gps_position &gp)
{
    return os << ' ' << gp.degrees << (unsigned char)186 << gp.minutes << '\'' << gp.seconds << '"';
}

posted on 2006-05-15 17:26 Beginning to 编程 阅读(825) 评论(1)  编辑 收藏 引用 所属分类: 关键代码

评论

# re: boost serialize 和 ostream 问题 2006-05-15 18:40 Squirrel

iostream 是输入输出流。
控制台输入输出(cout ,cin)是由该类派生出来的。
重载流操作以后,对一些常见流,如fstream 文件流、stringstream字符串流都有效。
也就是说,你可以把对象导到控制台、文件、内存等许多地方。
他的这个例子里,重载流操作和boost的序列化没有任何关系。不实现重载流操作,序列化照样工作。  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


导航

统计

常用链接

留言簿(4)

随笔分类

随笔档案

文章档案

相册

BlogDev

搜索

最新评论

阅读排行榜

评论排行榜