Learn how to use the boost Library (Windows XP + vc6.0)

Source: Internet
Author: User

1. Download

Download boost_000038_0.zip and boost-jam-3.1.17-1-ntx86.zip from www.boost.org.

2. Install the build tool bjam

Decompress boost-jamto bjam.exe and copy it to the path (for example, "Windows directory "),
The system should be able to find the executable bjam.exe file when the bjamcommand is executed in the command environment.

 

3. Install the boost Library

Decompress boost_000038_0.zip to the path where you are about to install boost. We recommend that you select a partition with sufficient space and unzip it to nearly 200 MB;
For example, if I want to install it in Zone C, create a boost folder in Zone C and decompress the compressed package to open C:/Boost/boost_000038_0.
You can see a bunch of folders and files.

 

4. Add Environment Variables

My computer-> properties-> advanced-> environment variables, add environment variables to user variables:

Boost_build_path value: C:/Boost/boost_1_38_0/tools/build/v2/

 

5. Configure the compiling environment

C:/Boost/boost_1_38_0/tools/build/V2 in the user-config.jam file, add the last line:

Using msvc: 6.0: D:/program files/Microsoft Visual Studio/vc98/bin/Cl;

Note the uplink format. The colon must have spaces on both sides, and the last semicolon must have spaces (because the C ++ Code does not
Due to such strict format restrictions, I didn't pay too much attention at the beginning and couldn't solve the error. I finally tried to find the cause ).

 

6. Create Hello world!

Now you can use bjam to create an application. Write Hello world and find a sense of accomplishment.
Create the file D:/test/Boost/Hello. cpp (the path is random. I like to put all the exercise programs in a test folder,
Then, place the VC exercise in the D:/test/VC/file, and the GCC exercise in the D:/test/GCC/folder. Of course, create another D for the boost exercise: /test/Boost), hello. the CPP content is as follows:
// <
# Include <iostream>
Using namespace STD;
Int main ()
{
STD: cout <"Hello, world! ";
Return 0;
}
//>

Create a text file named jamroot in the folder D:/test/Boost/Hello/. The content is as follows ):
# Jamfile for project hello

EXE Hello: Hello. cpp;

Install Dist: Hello: <location> .;

Go to the CMD command line and enter the project path: D:/test/Boost/Hello/>

Execute the compilation command: D:/test/Boost/Hello/> bjam hello;
The bin/msvc-6.0/debug/threading-multifolder is generated under the folder, and the hello.exe file is compiled in it

Run the command D:/test/Boost/Hello/> bjam Dist;
The generated hello.exe file will be copied to D:/test/Boost/Hello /.

Run Hello World: D:/test/Boost/Hello/> hello;
You will see the cute Hello, world!

 

7. Use the boost Library

Modify the hello. cpp file as follows:

# Include <iostream>
# Include <string>
# Include <boost/lexical_cast.hpp>
Using namespace STD;

Int main ()
{
// STD: cout <"Hello, world! ";

String STR = "520 ";

Try
{
Cout <boost: lexical_cast <int> (STR) <Endl;
}
Catch (boost: bad_lexical_cast & E)
{
Cerr <"Bad cast:" <E. What () <Endl;
}

Return 0;
}

If this is the case, the system will prompt that the boost/lexical_cast.hpp file cannot be found,
You need to modify the jamroot file and add the boost path:

# Jamfile for project hello

EXE Hello: Hello. cpp: <include> C:/Boost/boost_000038_0 /;

Install Dist: Hello: <location> .;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.