About C++ basic knowledge, you must know these professional terms(3)

The road is hindered and long, and the line is coming. Keep your head down and work hard, if you don't call it, it's a blockbuster! Come on, Sao Nian!

1 Introduction

  Based on "C++ Primer" 5th Edition, Chapter 3 "Strings, Vectors and Arrays" summarized;

  Tip: Be good at using shortcut keys to quickly search for relevant content! Ctrl + F

2 Chapter Summary

  • string And are the two most important standard library containers; vector
  • string An object is a variable-length character sequence, and an object is a set of containers of the same type; vector
  • Iterators allow indirect access to the objects in the container. For objects and objects, you can access elements or move between elements through the iterator; string vector
  • Arrays and pointers to array elements implement the standard library types and similar functions at a lower level ; string vector
  • Generally speaking, the types provided by the standard library should be used first, and then the low-level replacement arrays or pointers built into the language should be considered . C++

3 Glossary

  • begin

  It is a member of string and vector and returns an iterator to the first element. It is also a standard library function. Input an array and return a pointer to the first element of the array;

  • 缓冲区溢出(buffer overflow)

  A serious program failure. The main reason is trying to access the contents of the container through an out-of-bounds index. The container types include string, vector, array, etc.;

  • C 风格字符串(C-style string)

  A null-terminated character array. String literals are C-style strings, and C-style strings are prone to errors.

  • 类模板(class template)

  Used to create templates for concrete class types. To use a class template, you must provide auxiliary information about the type. For example, to define a vector object, you need to specify the type of element: vector contains elements of type int.

  • 编译器扩展(compiler extension)

  A particular compiler is an additional feature of the C++ language. Programs written based on compiler extensions are not easy to transplant to other compilers.

  • 容器(container)

  Is a type whose objects contain a set of objects of a given type. vector is a type of container.

  • 拷贝初始化(copy initialization)

  Use the initialization form of the assignment sign =. The newly created object is a copy of the initial value.

  • difference_type

  A signed integer type defined by string and vector, representing the distance between two iterators.

  • 直接初始化(direct initialization)

  The initialization form of assignment sign = is not used.

  • empty

  It is a member of string and vector and returns a boolean value. It returns true when the size of the object is 0, otherwise it returns false.

  • end

  It is a member of string and vector and returns an iterator after the end. It is also a standard library function that inputs an array and returns a pointer to the next position of the last element of the array.

  • getline

  A function defined in the string header file takes an istream object and a string object as input parameters. This function first reads the content of the input stream until it stops with a newline character, then saves the read data into a string object, and finally returns an istream object. The newline character is read in but not preserved.

  • 索引(index)

  Is the value used by the subscript operator. Represents a location to be accessed in a string object, vector object, or array.

  • 实例化(instantiation)

  The process by which the compiler generates a specified template class or function.

  • 迭代器(iterator)

  Is a type used to access elements in a container or move between elements.

  • 迭代器运算(iterator arithmetic)

  It is the operation of string or vector iterators: adding or subtracting an iterator to an integer results in a new iterator. Compared with the original iterator, the new iterator moves forward or backward by several positions. Two iterators are subtracted to get the distance between them. At this time, they must point to the element of the same container or the next position of the last element of the container.

  • 以空字符结束的字符串(null-terminated string)

  Is a string, and its last character is followed by a null character'\0'.

  • 尾后迭代器(off-the-end iterator)

  The iterator returned by the end function points to a non-existent element that is located next to the last element of the container.

  • 指针运算(pointer arithmetic)

  Arithmetic operations supported by pointer types. The types of operations supported by pointers to arrays are the same as iterator operations.

  • prtdiff_t

  It is a signed integer type defined in the cstddef header file and related to machine implementation. Its space is large enough to represent the distance between any two pointers in the array.

  • push_back

  It is a member of vector and adds elements to the end of the vector object.

  • 范围 for 语句(range for)

  A control statement that can iterate within a specific set of values.

  • size

  It is a member of string and vector, and returns the number of characters or the number of elements, respectively. The type of the return value is size_type.

  • size_t

  It is an unsigned integer type defined in the cstddef header file and related to machine implementation. Its space is large enough to represent the size of any array.

  • size_type

  It is the name of the type defined by string and vector, which can store the size of any string object or vector object. In the standard library, size_type is defined as an unsigned type.

  • string

  Is a standard library type that represents a sequence of characters.

  • using 声明(using declaration)

  Make a name in the namespace can be used directly by the program. The role of the program is to make the following statement of program names can be used directly, without having to write its prefix portion of the namespace :: .

using 命名空间::名字;
  • 值初始化(value initialization)

  It is an initialization process. The built-in type is initialized to 0, and the class type is initialized by the default constructor of the class. Only when the class contains a default constructor, the objects of that class will be value-initialized. For container initialization, if only the size of the container is specified without specifying the initial value, value initialization will be performed. At this time, the compiler generates a value, and the elements of the container are initialized to that value.

  • vector

  Is a standard library type that contains a set of elements of a specified type.

  • ++ 运算符(++ operator)

  It is an increment operator defined by iterators and pointers. Performing the "plus 1" operation makes the iterator point to the next element.

  • [] 运算符([] operator)

  Subscript operator. obj[j] gets the element at position j in the container object obj. The index starts from 0, the index of the first element is 0, and the index of the last element is obj.size()-1. The return value of the subscript operator is an object. If p is a pointer and n is an integer, then p[n] is equivalent to *(p + n).

  • -> 运算符(-> operator)

  Arrow operator, this operator has a comprehensive understanding of reference operations and dot operations. a->b is equivalent to (*a).b.

  • << 运算符(<< operator)

  The output operator defined by the standard library type string is responsible for outputting the characters in the string object.

  • >> 运算符(>> operator)

  The input operator defined by the standard library type string is responsible for reading a set of characters. When it encounters a blank, it stops. The read content is assigned to the operand on the right side of the operator, which should be a string object.

  • ! 运算符(! operator)

  The logical negation operator reverses the Boolean value of its operand. If the operand is false, the result is true; if the operand is true, the result is false.

  • && 运算符(&& operator)

  The logical AND operator, if both operands are true, the result is true. Only when the left operand is true will the right operand be checked.

  • || 运算符(|| operator)

  Logical OR operator, any operand is true, the result is true. Only when the left operand is false will the right operand be checked.

If the content of the article is wrong, please comment / private message a lot of advice! If you think the content of the article is not bad, remember to click three links (like, favorite, leave a message), if you can still click, it will be a greater encouragement to me, and it will be my motivation for creation, thank you !

Guess you like

Origin blog.csdn.net/fighting_boom/article/details/108858674