Wednesday, September 21, 2011

C++ BOOST LIBRARIES









REVISED: Sunday, March 3, 2013



CONTENTS:
I. C++ BOOST LIBRARIES INTRODUCTION
II. DOWNLOADING C++ BOOST LIBRARIES
III. INSTALLING C++ BOOST LIBRARIES

YOU WILL LEARN HOW TO:
1. DOWNLOAD THE C++ BOOST LIBRARIES.
2. INSTALL THE C++ BOOST LIBRARIES ON MICROSOFT WINDOWS VISUAL STUDIO.

I. C++ BOOST LIBRARIES INTRODUCTION


Welcome to the, “C++ BOOST LIBRARIES TUTORIAL.”


The C++ Boost 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 C++ Boost Libraries on Microsoft Windows Visual Studio.

II. DOWNLOADING C++ BOOST  LIBRARIES


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

http://www.boost.org/


The C++ Boost 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 C++ BOOST  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:

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:

#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:

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

10.  From the Debug menu, select:

Start Debugging.

The output should be as follows:

view source print?

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


YOU HAVE LEARNED HOW TO:
1. DOWNLOAD THE BOOST C++ LIBRARIES.
2. INSTALL THE BOOST C++ LIBRARIES ON MICROSOFT WINDOWS VISUAL STUDIO.

Elcric Otto Circle



-->

-->

-->







How to Link to My Home Page

It will appear on your website as:
"Link to ELCRIC OTTO CIRCLE's Home Page"




No comments:

Post a Comment