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)