Boost library Learning

Source: Internet
Author: User
ArticleDirectory
    • Lexical_cast
    • Timer

Download from www.boost.org, you can also download from the domestic image boost.c-view.org, I download version is 1.31, as if 1.32 is coming out. Direct
After downloading and decompressing it, you can use it. during compilation, you must add the boost path to the command line. Most of the boost components can be used directly. In addition, some components need to be compiled for platform reasons.
Library. Currently, I have not compiled the library myself.

Lexical_cast

Lexical_cast is used for type conversion. It can be a string-> value, or a value-> string. Easy to use,
When converting a string to a numeric value, first include the header file # include <boost/lexical_cast.hpp>, and then use: int
= Boost: lexical_cast <int> ("123"); that is, the string "123" can be converted to 123 of the int type.

Array-> String Conversion is the same, for example, string S = boost: lexical_cast <string> (123.12 );

If the conversion fails, a bad_lexical_cast exception will be thrown, which is a subclass of bad_cast.

Boost depends on the upstream stream STD: stringstream. Its principle is to read the source type into the upstream stream and then write it to the target type.

Lexical_cast is not limited to conversions between string and numeric types. It can be converted between any type that can be output to stringstream or any type that can be input from stringstream.

Timer

Boost provides the Timer class for timing, and the timer Time Report class progress_timer and progress bar display class progress_display.

The timer class is included in the boost/Timer. HPP header file, and the progress_timer and progress_display classes are included in boost/progress. HPP.

Timer MeasurementProgramIt uses the clock () function of the standard library, which has good portability, but the cost is not high accuracy.

The progress_timer class automatic measurement program is time-consuming and displays time-consuming information when it is an object. By default, It outputs character information to STD: cout. For example, generate a progress_timer object t in main, and output the execution time on the screen at the end of the program.

The progress_display class displays the progress bar at an appropriate position in an appropriate form. For example, you can execute a for loop to generate an object.
Progress_display show_progress (10000); then, during the execution of this for loop, let the object Add: For (int
I = 0; I <10000; I ++) {++ show_progress ;}, so that the progress bar is displayed while executing.

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.