Vector Learning ABC for C + +

Source: Internet
Author: User

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 + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.