这几天写代码需要序列化自定义类,类的定义可以抽象为vector<vector<T> >。我本想通过重载operator<<和operator>> 来实现序列化。但是写入是写入了,读就读不出来了。在读完第一个对象之后istream的tellg()返回了-1,导致后续的对象无法读取。后来我使用boost很方便的就完成了序列化的工作。但是我使用的编译环境是VC9,boost还没有针对vc9的编译设置,所以编译安装还是花了点时间。
针对VC9,下载的boost需做如下修改:(+为需增加的行,)
文件 msvc.jam
@@ -231,6 +231,10 @@ local rule configure-really (
{
# Even if version is not explicitly specified, try to detect the version
# from the path.
+ if [ MATCH "(Microsoft Visual Studio 9.0)" : $(command) ]
+ {
+ version = 9.0 ;
+ }
if [ MATCH "(Microsoft Visual Studio 8)" : $(command) ]
{
version = 8.0 ;
@@ -913,13 +916,14 @@ actions compile.mc
.ProgramFiles = [ path.make [ common.get-program-files-dir ] ] ;
-.known-versions = 8.0 8.0express 7.1 7.1toolkit 7.0 6.0 ;
+.known-versions = 9.0 9.0express 8.0 8.0express 7.1 7.1toolkit 7.0 6.0 ;
# Version aliases
.version-alias-6 = 6.0 ;
.version-alias-6.5 = 6.0 ;
.version-alias-7 = 7.0 ;
.version-alias-8 = 8.0 ;
+.version-alias-9 = 9.0 ;
# Name of the registry key that contains Visual C++ installation path
# (relative to "HKEY_LOCAL_MACHINE/SOFTWARE//Microsoft"
@@ -928,6 +932,8 @@ actions compile.mc
.version-7.1-reg = "VisualStudio//7.1//Setup//VC" ;
.version-8.0-reg = "VisualStudio//8.0//Setup//VC" ;
.version-8.0express-reg = "VCExpress//8.0//Setup//VC" ;
+.version-9.0-reg = "VisualStudio//9.0//Setup//VC" ;
+.version-9.0express-reg = "VCExpress//9.0//Setup//VC" ;
# Visual C++ Toolkit 2003 do not store its installation path in the registry.
# The environment variable 'VCToolkitInstallDir' and the default installation
文件 auto_link.hpp
line133开始改成:
#elif defined(BOOST_MSVC) && (BOOST_MSVC == 1400)
// vc80:
# define BOOST_LIB_TOOLSET "vc80"
#elif defined(BOOST_MSVC) && (BOOST_MSVC >= 1500)
// vc90:
# define BOOST_LIB_TOOLSET "vc90"
#elif defined(__BORLANDC__)
文件 visualc.hpp
#error "Compiler not supported or configured - please reconfigure"
#endif
//
-// last known and checked version is 1400 (VC8):
-#if (_MSC_VER > 1400)
+// last known and checked version is 1500 (VC9):
+#if (_MSC_VER > 1500)
# if defined(BOOST_ASSERT_CONFIG)
# error "Unknown compiler version - please run the configure tests and report the results"
# else
然后就可以编译了,但是在编译过程中会有很多的warning C4819: The file contains a character that cannot be represented in the current code page (936). 原因是boost源代码的注释中有很多非low ASCII的字符,都是人名和版权注释。在编译boost库时可以不管,但是在编译包含了boost的头文件的项目时却很烦人。可以在project properties, C/C++, Advanced, Disable Specific warnings中填入4819关闭这个警告。