omp vector.push_back()
时间: 2024-06-03 18:07:16 浏览: 89
OMP仿真.rar_omp_omp仿真
vector.push_back() is a member function of the C++ STL vector class that adds a new element at the end of the vector. The syntax for using this function is as follows:
vector.push_back(element);
Here, the "element" parameter is the value that needs to be added to the vector. The function increases the size of the vector by one and adds the element at the end.
For example, consider the following code snippet:
vector<int> v;
v.push_back(10);
v.push_back(20);
v.push_back(30);
for(int i=0; i<v.size(); i++) {
cout << v[i] << " ";
}
Output:
10 20 30
In this example, we create an empty vector "v" and then use the push_back() function to add three integers to the vector. Finally, we use a for loop to print the contents of the vector.
阅读全文