- 浏览: 259369 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (263)
- mysql (5)
- boost (6)
- 工具 (10)
- IT生活 (7)
- 多线程 (3)
- Ruby (15)
- php (2)
- MongoDB (39)
- 移动互联网 (2)
- 测试 (8)
- c++ (28)
- 书 (1)
- 网站 (3)
- 网络编程 (14)
- 开源软件 (1)
- 分布式计算 (1)
- 得得得 (1)
- php,wordpress (1)
- error (5)
- 编译 (2)
- 学习 (1)
- 杀毒软件 (1)
- dd (0)
- linux (21)
- 数据库 (1)
- STL (1)
- c++/c (5)
- 软件设计 (1)
- 操作系统 (4)
- 库 (2)
- win32 (1)
- s (0)
- openssl (1)
- perl (2)
- debug (1)
- windows (4)
- python (12)
- windows 防火墙 (1)
- vs (1)
- vim (2)
- vc (1)
- 浏览器插件的危害 (1)
- curl (0)
- 判断手机号码合法性的库 (0)
- 地址备注 (0)
- 安装 File::Slurp (1)
- cenos (2)
- shell (1)
- linunx (1)
- internet (1)
- software (1)
- widows (1)
- linux io (1)
- nginx (2)
- 算法 (2)
- google (1)
- protobuf (2)
- tengine (1)
- tools (1)
- lua (2)
- liunx (1)
- vcard (1)
- lua-iconv (1)
- 网络 (2)
- teat (0)
- ldconfig linux (0)
- awk (0)
- grep (0)
- windws (2)
- linux 命令 (1)
- tcp dump (1)
- vmware (1)
- question2answer (2)
- mongdb (1)
- 正则 (1)
- OCR (2)
- Windows Server (1)
最新评论
根据官方文档改写:
http://www.boost.org/doc/libs/1_45_0/libs/serialization/doc/tutorial.html#arrays
http://www.fuzhijie.me/?p=62
http://www.boost.org/doc/libs/1_45_0/libs/serialization/doc/tutorial.html#arrays
http://www.fuzhijie.me/?p=62
#include "stdafx.h" #include <windows.h> #include <process.h> #include <iostream> #include <exception> #include <assert.h> #include <fstream> //include headers that implement a archive in simple text format #include "boost/archive/text_oarchive.hpp" #include "boost/archive/text_iarchive.hpp" #include "boost/archive/binary_iarchive.hpp" #include "boost/archive/binary_oarchive.hpp" #include "boost/serialization/vector.hpp" #include "boost/serialization/string.hpp" #include "boost/iostreams/stream.hpp" #pragma command(lib, "boost_serialization-vc100-mt-1_48.lib") #pragma command(lig, "boost_iostreams-vc100-mt-1_48.lib"); using namespace std; ///////////////////////////////////////////////////////////// // gps coordinate // // illustrates serialization for a simple type // typedef struct gps_struct { char name[100]; char data[2][100]; string version; int id; }gps_struct; class gps_position { public: // friend class boost::serialization::access; // // when the class Archive corresponds to an output archive, the // // & operation 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; // } int degrees; int minutes; float seconds; vector<string> hellos; gps_struct time; public: gps_position(){}; gps_position(int d, int m, float s) : degrees(d), minutes(m), seconds(s) { hellos.push_back("test1"); hellos.push_back("test2"); hellos.push_back("test3"); strcpy(time.name, "Kevin He"); time.version = "1.0"; time.id =100; strcpy(time.data[0], "time1"); strcpy(time.data[1], "time2"); } }; namespace boost { namespace serialization { template<class Archive> void serialize(Archive & ar, gps_struct & g, const unsigned int version) { ar & g.id; ar & g.name; ar & g.version; ar & g.data; } template<class Archive> void serialize(Archive & ar, gps_position & g, const unsigned int version) { ar & g.degrees; ar & g.minutes; ar & g.seconds; ar & g.hellos; ar & g.time; } } // namespace serialization } // namespace boost int _tmain(int argc, _TCHAR* argv[]) { //create and open a character archive for output std::ofstream ofs("filename"); const gps_position g(35, 59, 24.57); //save data to archive char buffer[4096]; int bufferSize = 4096; string mydata; { //boost::archive::text_oarchive oa(ofs); memset(buffer, 0, bufferSize); boost::iostreams::basic_array<char> sr(buffer, bufferSize); boost::iostreams::stream< boost::iostreams::basic_array<char> > source(sr); boost::archive::text_oarchive oa(source); //write class instance to archive oa << g; //archive and stream closed when destructors are called; } gps_position newg; { //std::ifstream ifs("filename"); //boost::archive::text_iarchive ia(ifs); // read class state from archive boost::iostreams::basic_array<char> sr(buffer, bufferSize); boost::iostreams::basic_array<char> temp(buffer, bufferSize); boost::iostreams::stream< boost::iostreams::basic_array<char> > newsource(temp); boost::archive::text_iarchive ia(newsource); ia >> newg; } // ... some time late restore the class instance to its orginal state return 0; }
发表评论
-
c++ 读取unicode文档
2015-02-09 16:12 915int ReadOneNameFile(char *fil ... -
http://curl.haxx.se/
2013-06-13 17:41 0http://curl.haxx.se/ -
[转]线程本地存储(Thread Local Storage, TLS)分析与使用
2013-05-03 16:53 774线程本地存储(Thread Local Storage, TL ... -
C/C++获得windows版本
2012-12-01 11:05 1401MSDN上有详细介绍,做个标记: #include & ... -
[转]异常处理与MiniDump详解(4) MiniDump
2012-10-24 14:46 931异常处理与MiniDump详解(4) MiniDump wri ... -
禁用系统硬错误消息对话框
2012-08-31 19:14 693http://support.microsoft.com/kb ... -
Application Crash Dump Analysis (Windows 7)
2012-08-28 09:39 0Application Crash Dump Analysis ... -
如何成为一个windows程序debug高手
2012-08-18 14:40 0minidump: http://blog.csdn.ne ... -
Boost库编译后命名方式
2012-05-17 10:29 1282Boost官网的《Geting Started ... -
geoIP
2012-05-14 12:38 0http://www.oschina.net/code/sni ... -
vs2010 断点 无法命中
2012-05-07 16:13 1317这种情况不解决办法有 很多。你这个方法我没用过。最简单的方法就 ... -
$err,hr
2012-05-04 20:43 851在Visual C++ 中,可以在监视窗口添加 $err,hr ... -
WINDOWS下线程同步探讨
2012-04-11 15:04 923概述 线程同步可 ... -
undefined reference to 'pthread_create'问题解决
2012-03-30 11:43 0由于是Linux新手,所以现在才开始接触线程编程,照着GUN/ ... -
linux 下 遍历文件夹下的内容
2012-03-29 19:43 0// only works in cpp #ifdef __c ... -
浅谈ReadDirectoryChangesW函数的作用和问题所在
2012-03-23 10:32 4249转自:http://www.cnblogs.com ... -
用 _findfirst 和 _findnext 查找文件,遍历文件夹
2012-03-30 11:39 1986标签: _findfirst _findnext 杂谈 分类: ... -
我的广告
2012-03-19 10:57 0http://www.webweb.com/signup.as ... -
服务器多服务器设置
2012-03-12 18:01 724当服务器功能比较多时,可以抽象出一个代理,将不同的服务 ... -
记录个函数 strstr
2012-03-10 11:30 989包含文件:string.h 函数名: strstr 函 ...
相关推荐
C# 数组与序列化C# 数组与序列化C# 数组与序列化C# 数组与序列化C# 数组与序列化C# 数组与序列化C# 数组与序列化
boost类序列化
C#中二进制数组h和各种常规数组的转换,二进制序列化和json序列化方法以及对应的反序列化方法的例子,帮助初学者。
C# 读取序列化后的数组C# 读取序列化后的数组C# 读取序列化后的数组C# 读取序列化后的数组C# 读取序列化后的数组
asp.net 数组与序列化! 很值得下载看看!资源免费,大家分享!!
C++11 下使用 Boost.Serialization 库实现智能指针的序列化
1、包含文件和二进制两种序列化的方式 2、支持类的序列化和STL容器的序列化 3、支持序列化的流自定义(示例中使用的是std::stringstream,也可以使用其他的流)
base64序列化字符串,用于传输,避免传输过程中转义符错误。
创建适用于URL查询字符串或Ajax请求的数组,普通对象或jQuery对象的序列化表示形式。 如果jQuery对象被传递,它应该包含具有name / value属性的输入元素。 jQuery.param( obj ): obj: 类型:Array或PlainObject或...
数组 求连续子序列最大和程序 时间复杂度O(n) 空间复杂度O(1)
序列化和反序列化的封装类,只要调用就行 序列化和反序列化的封装类 序列化和反序列化的封装类 序列化和反序列化的封装类 序列化和反序列化的封装类
时间序列分析 一个时间序列通常由4种要素组成:趋势、季节变动、循环波动和不规则波动。 趋势:是时间序列在长时期内呈现出来的持续向上或持续向下的变动。 季节变动:是时间序列在一年内重复出现的周期性波动。它是...
1.使用xson进行对象到字节数组的序列化 User user = new User(); //set.... byte[] data = XSON.write(user); 2.使用xson进行字节数组到对象的反序列化 //byte[] data = XSON.write(user); User user...
将Class或Struct序列化成Byte数组或序列化成Xml,并有压缩功能
我们都知道对象是暂时保存在内存中的,不能用U盘考走了,有时为了使用介质转移对象,并且把对象的状态保持下来,就需要把对象保存下来,这个过程就叫做序列化,通俗点,就是把人的魂(对象)收伏成一个石子(可传输...
极好的序列化与发序列化代码。可以处理array集合,数组或者单个对象等的序列化与反序列化。
c语言 c语言编程题之数组操作非递减序列
解决socket网络中通信的序列化和反序列化问题,很好的实例
主要介绍了实例解析Json反序列化之ObjectMapper,json自定义序列化的方法,需要的朋友可以了解下。