如果您习惯于传统CVS的命令行模式,那么可在Admin→Command Line...→Command line settings中输入下面一行[]: cvs -z3 -d:pserver:anonymous@cvs.boost.sourceforge.net:/cvsroot/boost checkout boost 勾上下面的复选框,选择本地目标目录(比如可以新建一个C:\Boost,这凭个人爱好),再点击确定即可开始更新。如果是第一次运行,则可能需要一段时间下载所有文件。当然以后更新就只需要很短的时间了。
如果您偏好GUI模式,请选择Admin→Preferences...,在General的Enter CVS ROOT中填写: anonymous@cvs.boost.sourceforge.net:/cvsroot/boost Authentication
选择"passwd" file on the cvs server,同时Use version选择cvs 1.10
(standard)。然后在WinCvs的HOME folder中填写或选择一个本地目标目录,点击确定。选择View→Browse
Location→Change...换到本地目标目录后,在Create→Check Module...→Checkout
Settings的Enter the module name and path on the
server中填写boost,单击确定即可。如果这一过程中要求输入密码,不必理会,直接回车就行。这是WinCVS
1.2的情况。如果您下载的是新的版本,请注意各项设置大同小异,如前面的Authentication选择pserver、不需要设置Use
version等。
然后设置编译器。以Windows常用集成环境为例。Microsoft Visual C++
6.0,可在工具→选择→目录处把Boost的路径(如前面的boost_1_26_0)添加到Include
Files搜索路径中。而对于Borland C++ Builder
5.0,则是在Project→Options→Directories/Conditionals→Include
Path中添加Boost的路径。还有一种比较常用的Dev-C++ 4.0(内置GNU C++,可从处
免费下载),可在Options→Compile Options→Directories→C++ include
files处添加Boost的路径即可。其他IDE类似。至于命令行方式,则需在编译时对相应的头文件路径参数(Borland C++
Compiler、GNU C++是-I,VC++的cl是/I)给出Boost路径。
#include #include int main() { using boost::lexical_cast; int a = lexical_cast("123"); double b = lexical_cast("123.12"); std::cout< std::cout< return 0; }
[] 非常感谢Andrew Koenig和Bjarne Stroustrup两位的指教和帮助。最开始我的想法是,指定最大精度,加入interpreter.precision(15)之
类的语句,然而又担心移植性的问题。Andrew Koenig先生给出了非常明确的解释:You are quite correct that
15 is not portable across all floating-point implementations. However,
it is portable across all implementations that support IEEE
floating-point arithmetic, which is most computers that are in common
use today. If you want to do better than that, you might consider using
numeric_limits::digits10, which is the
number of significant base-10 digits that can be accurately represented
in a
double.(中文大意是,诚然,15并非可移植到所有浮点实现中,但对于支持IEEE浮点运算的实现来说,则的确是可移植的,而且,这也是现今绝大部
分计算机所使用的。如果想做得更好一点,则可以考虑使用numeric_limits::digits10,就能表示出10进制下double能精确表达的位数。)