began to learn and use the vector, and then to learn the feeling of miracles, like a run can give a sugar to eat haha
Baidu on the six kinds of initialization method is no longer said, those methods are very right.
Just not in line with my user needs haha
First, the header file
#include <vector>
Then, define a vector
Vector<int> A;
Here, the A can initialize it in six ways, but I don't need it here. I began to think that I had to initialize to apply for memory, and later found out that it would apply when push_back. Such
for (int k=0; k<10;k++) A.push_back (B[k]);
Look at other people's Code, with a[k] = B[k], similar method assignment, but I run here is a failure, in the end can not write this is not sure.
Traversal is using its own function.
for (Vector<int>::iterator iter = A.begin (); ITER! = A.end (); ++iter, ++i) { c[i] = *iter;}
Above, basic usage
Report:
#include <iostream> #include <vector>int j;using namespace std;int main (int argc, char **argv) {Vector<int > A; int b[10] = {9}; cout<< "Number of inputs:" <<endl; for (int k=0; k<10;k++) A.push_back (b[k]), int *c=new int[a.size ()]; size_t i=0; for (vector<int>::iterator iter = A.begin (); ITER! = A.end (); ++iter, ++i) { c[i] = *iter;} for (j = 0; J < a.size (); ++j) cout << * (c + j) <<endl; Delete [] C; r Eturn 0;}
Castle Peak does not change the green water still, next see
Vector Learning ABC for C + +