Reading Notes: C ++ STL Development Technology Guide-1

Source: Internet
Author: User

 

Chapter 2 C ++ Programming Technology

1.6 display type conversion

Prototype for conversion of four display types

Reinterpret_cast conversion:

Const_cast conversion:

Static_cast conversion:

Dynamic_cast conversion:

 

1.7 Exception Handling in C ++

Correspondence between multiple try blocks and catch Blocks

Catch exceptions of any type

Exception type list, declaring that no exception is thrown

An exception is thrown when the exception type list is violated.

Another common Exception Handling Method: continue to throw an exception and let the caller handle the exception

$1.9 function declaration can be placed anywhere in the class

Chapter 2 C ++ template Technology

The template Technology in C ++ is the basis for the implementation of algorithms and containers in STL. The introduction of the template is to promote the pre-processing macro in C to C ++.

Typename can indicate that a flag is of a type.

Class template Definition

2.3 Special template Technology

This technology improves the template's customization functions for functions or classes.

The function template is completely special, and the class template is completely special

 

All features are all features, that is, all template parameters are features. Partial features are partial features, that is, specific parameters of some templates.

Full and Partial features are not strictly defined, so sometimes they are not easy to understand.

Example:

Template <Class U, class T>

Class C {};

All features:

Template <>

Class C <int, char> {};

Special features:

Template <Class U>

Class C <u, int> {};

 

Let's look at the following example:

Template <class T, Class U>

Class C <t *, u *> {};

This is also template-specific.

 

2.4 function template overload

2.5 class template inheritance

Chapter 2 I/O stream technology in C ++

In the standard template library of C ++, a set of template classes and corresponding implementation classes are provided to support Object-oriented Data Input and Output Functions.

The C ++ stream class can implement object I/O operations, which is not available in C ++ Compatible C standard library I/O functions.

Derivative relationship of the template class of the I/O Stream class

The bottom layer of the I/O Stream class in C ++ is the template class basic_streambuf.

We can see that the frequently used istream, ostream, iostream, ifstream, ofstream, and fstreamd types are all redefined using typedef.

Implementation of stream classes in STL: http://www.cplusplus.com/reference/iostream/

3.3 input and output files

All file stream classes use open functions to open files.

File stream read/write

# Include <fstream>

# Include <iostream>

Using namespace STD;

 

Int main (void ){

Fstream rwfilestream;

Rwfilestream. Open ("d :\\ digit.txt", IOS: In | IOs: Out | IOs: Binary | IOs: trunc );

If (! Rwfilestream ){

Cout <"failed to open the file" <Endl;

Return 1;

}

For (char I = 0; I <26; I ++)

Rwfilestream <char ('A' + I); // write 26 letters

//

Rwfilestream. seekg (3, IOS: Beg); // locate 3rd letters (indexed from 0)

Char C;

Rwfilestream. Get (C );

Cout <C <Endl; // print the character d

Rwfilestream. Close ();

Return 0;

}

3.4 control of stream formats in C ++

(1) Use the function to set or reset the format

SETF Function Format

Other setting functions:

Width, precision, and fill

 

(2) Use the input and output operators to set the stream format

2nd basics of C ++ STL Generalization Technology

Chapter 2 Overview of C ++ STL generic Libraries

How to add the process proposed by STL to the standard

Various STL implementation versions

When compilation of STL programs fails, the debugging information provided by the compiler is generally obscure, and some key information can be captured for analysis.

4.4 C ++ STL Architecture

Containers in STL

Iterator in STL


Algorithm Implementation in STL


Function objects in STL

Adapters in STL


Memory distributor in STL


Concept and model in STL)


Some Problems in C ++ STL

Summary:

Chapter 3 General Technology Analysis of C ++ STL

Generalized implementation based on algorithms leads to generalization technologies related to iterators, function objects, and adapters.

Input_iterator_tag acting as a tag

5.1.4 Adapter

Iterator Adapter

Function Object Adapter

5.2 memory adapter and container

Memory adapter in STL

Use Vector to describe general container Generalization Technology

Base class of vector: vector_base class

Vector

Implementation of push_back function in Vector

When adding an element to a vector, place new technology is used:

5.3 concepts

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.