Home > Back-end >  C: how do the vector assignment?
C: how do the vector assignment?

Time:12-06

# c + + vector#
Normal vector can be assigned to it in the statement? Or must use C array?
In addition, the push_back is how the work? Is to put all the data forward displacement and crowd out first, or replace the last one? What's good about put the push_back in the loop?

CodePudding user response:

Vector Vec={1, 2, 3, 4, 5};
Push_back should be put in the end, and he is not a simple put, it is according to your incoming parameters to determine the replication, or mobile directly,
On the loop is just a normal operation, if there are 100000 data, 100000 line push_back? Don't you want to write?

CodePudding user response:

Name call push_back, the meaning of that is clearly pushing the tail,
Other, the bosses have been poking fun at the upstairs is very good, I will not ridicule

CodePudding user response:

Normal vector can be assigned to it in the statement?
Must be able to, not only vector, the map and list is also similar, the set and the queue didn't try, estimation is similar,

Did not study the push_back principle, however, there are recommended emplace_back replace push_back, specific can see the source code of the STL, I personally tend to use the push_back, because it is difficult to encounter a lot of work on data (except for a particular company)

CodePudding user response:

reference light bamboo hat reply: 3/f
normal vector can be assigned to it in the statement?
Must be able to, not only vector, the map and list is also similar, the set and the queue didn't try, estimation is similar,

Did not study the push_back principle, however, there are recommended emplace_back replace push_back, specific can see the source code of the STL, I personally tend to use the push_back, because it is difficult to encounter a lot of work on data (except for a particular company)

C + + 11, after the push_back internal call emplace_back is

CodePudding user response:

Can use vector A (n, {//initialization value n}); In this form?
Another vector, I declared n=3, how much it under the table from the start?

CodePudding user response:

How to end?

CodePudding user response:


The subscript is from 0 (index), to the end of the n - 1

CodePudding user response:

The push back () is a member function, push the value at the end of the day and to increase size 1

CodePudding user response:

The question is, how to cover a value?

CodePudding user response:

Iter=vec. Erase (iter);
Vec. Insert (iter);

CodePudding user response:

The
reference 5 floor Treasure. Ticdc response:
can use vector A (n, {//initialization value n}); In this form?
Another vector, I declared n=3, how much it under the table from the start?

Oh, yes, vector V (1, 2); Is there is a 10 v initialize values, each value is the size of the 2, but no vector V (10, {1, 2, 3... }) this kind of operation,

CodePudding user response:

Treasure, 9/f,
reference. Ticdc response:
the problem is, how to cover a value?

Covering a value like ordinary array assignment, such as vector V (10); Is to initialize v have ten values, each value is 0, you need to change the value of the zeroth element, v [0]=9, thus covering the value of v [0]

CodePudding user response:

1, are all upstairs. Suggestions can read, to check the information what, do you understand the first ~
2, recommend a site: https://zh.cppreference.com/w/cpp, they can look at,

Come on, I wish your good luck!

CodePudding user response:

refer to 12 floor shu Yang reply:
Quote: Treasure, 9/f, reference. Ticdc reply:
the problem is, how to cover a value?

Covering a value like ordinary array assignment, such as vector V (10); Is to initialize v have ten values, each value is 0, you need to change the value of the zeroth element, v [0]=9, thus covering the v [0] the value of the

This seems to be no good, the subscript in the vector is not only used to read

CodePudding user response:

reference Treasure. 15 floor ticdc response:
Quote: refer to the 12th floor of shu Yang reply:
Quote: Treasure, 9/f, reference. Ticdc reply:
the problem is, how to cover a value?

Covering a value like ordinary array assignment, such as vector V (10); Is to initialize v have ten values, each value is 0, you need to change the value of the zeroth element, v [0]=9, thus covering the v [0] the value of the

This seems to be no good, the subscript is not only used to read in the vector

Is not only used to read, also can assign a value, as in the C language a [0]=1; Like, I put a [0] value is 1
  • Related