Similar Books


    No books found

Title
Chapter: 3 / Q: e.g3.3.1.2
We can also supply initial value(s) for the element(s) when we define a vector. For example, we can copy elements from another vector. When we copy a vector, each element in the new vector is a copy of the corresponding element in the original vector. The two vectors must be the same type
Chapter: 3 / Q: e.g3.3.1.3
A third restriction is that we can supply a list of element values only by using list initialization in which the initializers are enclosed in curly braces. We cannot supply a list of initializers using parentheses
Chapter: 3 / Q: e.g3.3.1.4
We can also initialize a vector from a count and an element value. The count determines how many elements the vector will have; the value provides the initial value for each of those elements
Chapter: 3 / Q: e.g3.3.1.5
If the vector holds elements of a built-in type, such as int, then the element initializer has a value of 0. If the elements are of a class type, such as string, then the element initializer is itself default initialized
Chapter: 3 / Q: e.g3.3.1.6
The second restriction is that when we supply an element count without also supplying an initial value, we must use the direct form of initialization
Chapter: 3 / Q: e.g3.3.1.7
if we supply exactly two int values, those values could be a size and an initial value, or they could be values for a two-element vector. We specify which meaning we intend by whether we use curly braces or parentheses
Chapter: 3 / Q: e.g3.3.1.8
To list initialize a vector of strings, we must supply values that can be used as strings. In this case, there is no confusion about whether to list initialize the elements or construct a vector of the given size
Chapter: 3 / Q: e.g3.3.2.1
In such cases, it is better to create an empty vector and use a vector member named push_back to add elements at run time. The push_back operation takes a value and “pushes” that value as a new last element onto the “back” of the vector. For example
Chapter: 3 / Q: e.g3.3.2.2
We use the same approach when we want to create a vector where we don’t know until run time how many elements the vector should have. For example, we might read the input, storing the values we read in the vector
Chapter: 3 / Q: e.g3.3.3.1
We access the elements of a vector the same way that we access the characters in a string: through their position in the vector. For example, we can use a range for (§ 3.2.3, p. 91) to process all the elements in a vector
total questions: 591

Questions

591

Views

A PHP Error was encountered

Severity: Warning

Message: Undefined property: stdClass::$TotalViews

Filename: books/book.php

Line Number: 411

Best Answers

299

Points

5