Page 1 of 1

BOOST C++ LIBRARIES TUTORIAL BOOST C++ LIBRARIES TUTORIAL Rate Topic: -----

#1 Elcric  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 102
  • View blog
  • Posts: 453
  • Joined: 02-May 09

Posted 10 September 2009 - 10:28 AM

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:

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

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.

Is This A Good Question/Topic? 2
  • +

Page 1 of 1