C++ School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C++ Expert!

Join 307,172 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,553 people online right now. Registration is fast and FREE... Join Now!




BOOST C++ LIBRARIES TUTORIAL

 
Reply to this topicStart new topic

> BOOST C++ LIBRARIES TUTORIAL, BOOST C++ LIBRARIES TUTORIAL

Elcric
Group Icon



post 10 Sep, 2009 - 09:28 AM
Post #1


BOOST C++ LIBRARIES TUTORIAL


YOU WILL LEARN HOW TO:

1. DOWNLOAD THE BOOST C++ LIBRARIES.

2. INSTALL THE BOOST C++ LIBRARIES ON MICROSOFT WINDOWS VISUAL STUDIO 2008.

• I. INTRODUCTION

Hello; nice to meet you! Welcome to the, “BOOST C++ LIBRARIES TUTORIAL.”

C++0x is the working name for the next version of the C++ Standard. Technical Report 1 (TR1) and TR2 describe proposed changes to the C++ Standard. The TR1 and TR2 proposed changes include changes to the C++ Standard Template Library (STL); for example, adding some of the Boost C++ Libraries.

The existing C++ STL has provided tested solutions to common programming problems, shortened development cycles, and improved program quality. The Boost C++ Libraries are free open source libraries that are expected to continue the standard of excellence established by the STL.

This tutorial will cover downloading and installing Boost C++ Libraries on Microsoft Windows Visual Studio 2008.

• II. DOWNLOADING BOOST C++ LIBRARIES

There are many excellent Boost C++ Libraries free download websites to choose from, including the following:

http://www.boost.org/

The Boost C++ Libraries are constantly being updated with new additions. I have been using Boost C++ Libraries for a long time, my current download is:

C:\Program Files\boost\boost_1_35_0

It is a large download; however, follow the directions and respond when prompted and the download should not be a problem.

• III. INSTALLING BOOST C++ LIBRARIES

After you have successfully completed the download, the following steps can be used to install the Boost C++ Libraries on Microsoft Windows Visual Studio 2008:

1. From Visual Studio's File menu, select New > Project.

2. In the left-hand pane of the resulting New Project dialog, select Visual C++ >Win32.

3. In the right-hand pane, select Win32 Console Application Win32 Console Project.

4. In the name field, enter “boost”.

5. Right-click example in the Solution Explorer pane and select Properties from the resulting pop-up menu.

6. In Configuration Properties > C/C++ > General > Additional Include Directories, enter the path to the Boost root directory, for example:

C:\Program Files\boost\boost_1_35_0

7. In Configuration Properties > C/C++ > Precompiled Headers, change Use Precompiled Header to Not Using Precompiled Headers.

8. Replace the contents of the boost.cpp generated by the IDE with the example code below:

CODE

#include <vector>
#include <iostream>
#include <algorithm>
#include <boost/shared_ptr.hpp>

using namespace::std;

struct Boost_Example
{
  Boost_Example( int _x ) : x(_x)
  {

  }
  ~Boost_Example()
  {
      std::cout << "  Destroying Boost_Example x = " << x << "\n";
      std::cout << endl << endl << "  ";
      system("PAUSE");
      std::cout << endl << endl;
  }
  int x;
};

typedef boost::shared_ptr<Boost_Example> Boost_ExamplePtr;

struct Boost_ExamplePtrOps
{
  bool operator()( const Boost_ExamplePtr & a, const Boost_ExamplePtr & b )
  {
        return a->x < b->x;
  }
  void operator()( const Boost_ExamplePtr & a )
  {
        std::cout << " " << a->x;
  }
};

int main()
{
  std::vector<Boost_ExamplePtr> Boost_Example_vector;

  Boost_Example_vector.push_back( Boost_ExamplePtr(new Boost_Example(3)) );
  Boost_Example_vector.push_back( Boost_ExamplePtr(new Boost_Example(2)) );
  Boost_Example_vector.push_back( Boost_ExamplePtr(new Boost_Example(1)) );

  std::cout << endl << endl;
  std::cout << "  Original Boost_Example_vector:  ";
  std::for_each( Boost_Example_vector.begin(), Boost_Example_vector.end(), Boost_ExamplePtrOps() );
  std::cout << "\n";

  std::sort( Boost_Example_vector.begin(), Boost_Example_vector.end(), Boost_ExamplePtrOps() );

  std::cout << endl << endl;
  std::cout << "  Sorted Boost_Example_vector:    ";
  std::for_each( Boost_Example_vector.begin(), Boost_Example_vector.end(), Boost_ExamplePtrOps() );
  std::cout << "\n";

  std::cout << endl << endl << "  ";
  system("PAUSE");
  std::cout << endl << endl;
  return 0;
  
}


9. From the Build menu, select Build Solution.

When you have a successful build you should get the following message:

CODE

========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========


10. From the Debug menu, select Start Debugging.

The output should be as follows:

CODE

Original Boost_Example _vector: 3 2 1

Sorted Boost_Example _vector: 1 2 3

Destroying Boost_Example x = 1

Destroying Boost_Example x = 2

Destroying Boost_Example x = 3


If you have any problems please post your questions on the DIC forum.

Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/21/09 06:47PM

Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month