[c++]记录使用vector遇到过的天坑问题

/ 340评论 / 2940阅读 / 0点赞

vector

* vector是c++的一个模板容器,同时也是一个动态数组,是数组就意味着它支持随机访问。

* 它几乎与arraylist一样,但vector是线程安全的,因此vector的性能比arraylist弱。

* 使用时需要#include <vector>

注意

vector<int> arr;
for (int i = 10; i--;)		//向vector压入数据
	arr.push_back(i);

vector<int>::iterator it_p = arr.begin();//获取vector第一个的迭代器
for (; it_p < arr.end(); ++it_p)//依次顺序输出
	cout << *it_p << " ";

cout << arr.back() << endl;	//输出最后一个元素的值

it_p = arr.begin();
it_p += 4;			//把迭代器移动4个位置
cout << *(it_p - 3) << endl;	//不会报错
//cout << *(it_p - 6 + 3) << endl;//如果编译器有优化提前计算出了结果-3,则不会报错
int a = 6, b = 3;
//cout << *(it_p - a + b) << endl;//会报错

  1. free cam sex说道:

    You’re so cool! I do not believe I have read through something like this before. So wonderful to find another person with a few genuine thoughts on this issue. Seriously.. thank you for starting this up. This site is one thing that is required on the internet, someone with a little originality.

  2. 부평오피说道:

    Greetings! Very useful advice in this particular article! It’s the little changes which will make the greatest changes. Thanks for sharing!

  3. mağaza poşeti说道:

    Hi there! I could have sworn I’ve been to this blog before but after looking at some of the posts I realized it’s new to me. Anyhow, I’m certainly delighted I discovered it and I’ll be book-marking it and checking back often.

  4. Dannie Lodwick说道:

    Greetings! Very helpful advice within this post! It is the little changes that will make the greatest changes. Thanks for sharing!

  5. Can I just say what a relief to find a person that truly understands what they are discussing on the net. You certainly understand how to bring an issue to light and make it important. More and more people really need to look at this and understand this side of your story. It’s surprising you’re not more popular given that you most certainly possess the gift.

  6. 대구풀싸롱说道:

    This is the perfect blog for anyone who would like to understand this topic. You realize a whole lot its almost tough to argue with you (not that I personally would want to…HaHa). You definitely put a fresh spin on a topic that has been written about for many years. Great stuff, just wonderful.

  7. Spot on with this write-up, I actually believe that this amazing site needs much more attention. I’ll probably be returning to read more, thanks for the information!

  8. 헬로밤说道:

    An interesting discussion is worth comment. I believe that you ought to write more about this subject matter, it might not be a taboo subject but typically folks don’t speak about such issues. To the next! Many thanks!

  9. I’m impressed, I must say. Seldom do I come across a blog that’s equally educative and interesting, and without a doubt, you’ve hit the nail on the head. The problem is something that not enough folks are speaking intelligently about. Now i’m very happy that I stumbled across this during my hunt for something concerning this.

  10. EE88说道:

    After I initially commented I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on each time a comment is added I get 4 emails with the exact same comment. Is there a means you can remove me from that service? Cheers.

  11. Ho88说道:

    I’m amazed, I must say. Rarely do I encounter a blog that’s equally educative and entertaining, and without a doubt, you’ve hit the nail on the head. The problem is an issue that too few people are speaking intelligently about. Now i’m very happy I came across this during my hunt for something regarding this.

  12. live sex webcams说道:

    That is a good tip especially to those new to the blogosphere. Short but very accurate info… Thank you for sharing this one. A must read article!

  13. Hi! I could have sworn I’ve been to your blog before but after browsing through some of the posts I realized it’s new to me. Regardless, I’m certainly happy I stumbled upon it and I’ll be bookmarking it and checking back often!

  14. winning303说道:

    I pay a quick visit day-to-day some sites and sites to read content, except this
    web site gives feature based posts.

  15. It’s hard to come by experienced people about this topic, however, you seem like you know what you’re talking about! Thanks

  16. naga169说道:

    Thanks to my father who told me regarding this web site, this
    website is truly remarkable.

  17. naga169说道:

    At this time it seems like WordPress is the top blogging platform out there right
    now. (from what I’ve read) Is that what you are using on your blog?

  18. ufo5555说道:

    My brother recommended I would possibly like this web site.

    He was totally right. This submit truly made my day. You can not consider simply
    how so much time I had spent for this information! Thank you!

  19. naga169说道:

    Hi! I could have sworn I’ve visited this site before but after going
    through a few of the posts I realized it’s new to me.

    Anyhow, I’m certainly delighted I discovered it and I’ll be
    bookmarking it and checking back regularly!

  20. slot via qris说道:

    Hi there outstanding blog! Does running a blog such as this take
    a great deal of work? I have virtually no expertise in computer programming but I had been hoping to start my own blog soon.
    Anyways, if you have any recommendations or techniques for new blog owners please
    share. I understand this is off topic however I simply wanted
    to ask. Thank you!

  21. winning303说道:

    I’m impressed, I must say. Seldom do I come across a blog that’s equally educative and interesting,
    and without a doubt, you’ve hit the nail on the head.
    The problem is something which too few men and women are speaking intelligently about.
    I am very happy I came across this in my hunt for something
    concerning this.

  22. winning303说道:

    I like what you guys are usually up too. Such clever work and reporting!
    Keep up the fantastic works guys I’ve added you guys to blogroll.

  23. winning303说道:

    For the reason that the admin of this web page is
    working, no question very soon it will be famous, due to its feature contents.

  24. ufo5555说道:

    What’s up, I wish for to subscribe for this website to get most recent updates, so where can i do it please help out.

  25. Spot on with this write-up, I truly think this site needs far more attention. I’ll probably be returning to read more, thanks for the advice!

  26. ufoo555说道:

    Greetings from Idaho! I’m bored at work so I decided
    to check out your website on my iphone during lunch
    break. I enjoy the information you present here and
    can’t wait to take a look when I get home.
    I’m surprised at how quick your blog loaded on my mobile ..
    I’m not even using WIFI, just 3G .. Anyhow, awesome blog!

  27. winning303说道:

    Quality articles or reviews is the crucial to attract the visitors to pay a quick
    visit the website, that’s what this website is providing.

  28. Having read this I thought it was rather enlightening. I appreciate you spending some time and effort to put this informative article together. I once again find myself spending a lot of time both reading and leaving comments. But so what, it was still worthwhile!

  29. naga169说道:

    This is very interesting, You’re a very skilled blogger.

    I’ve joined your feed and look forward to seeking more of your magnificent post.

    Also, I’ve shared your web site in my social networks!

  30. ufo5555说道:

    Incredible points. Solid arguments. Keep up the great spirit.

  31. nataliaohar.com说道:

    You should be a part of a contest for one of the greatest blogs on the internet. I am going to recommend this website!

  32. FCB8说道:

    An interesting discussion is definitely worth comment. I believe that you ought to publish more about this topic, it might not be a taboo matter but typically people don’t discuss these subjects. To the next! Best wishes.

  33. Hello, There’s no doubt that your blog could possibly be having web browser compatibility issues. Whenever I look at your blog in Safari, it looks fine however, when opening in IE, it’s got some overlapping issues. I just wanted to give you a quick heads up! Apart from that, excellent site!

  34. Right here is the perfect website for anybody who hopes to find out about this topic. You know so much its almost hard to argue with you (not that I really will need to…HaHa). You certainly put a brand new spin on a topic which has been written about for ages. Excellent stuff, just great.

  35. Slot qris说道:

    This post is priceless. Where can I find out more?

  36. naga169说道:

    An interesting discussion is worth comment. I do think that you should publish more about this topic,
    it may not be a taboo subject but generally people do not
    speak about these subjects. To the next! Many thanks!!

  37. Having read this I believed it was rather enlightening. I appreciate you taking the time and effort to put this informative article together. I once again find myself spending way too much time both reading and commenting. But so what, it was still worthwhile!

  38. naga169说道:

    Great beat ! I would like to apprentice while you
    amend your site, how can i subscribe for a blog site?

    The account helped me a acceptable deal. I had been tiny bit acquainted
    of this your broadcast offered bright clear idea

  39. winning303说道:

    Undeniably consider that that you stated. Your favourite justification appeared to be
    at the internet the easiest thing to have in mind of.

    I say to you, I definitely get irked while other people consider worries that they
    just don’t recognize about. You controlled to hit the nail upon the highest as smartly as outlined out
    the entire thing with no need side effect , folks can take
    a signal. Will likely be again to get more. Thank you

  40. ufoo555说道:

    Thanks for sharing your thoughts on c/c++. Regards

  41. winning303说道:

    Thanks designed for sharing such a fastidious thought, paragraph is pleasant, thats why i have read it entirely

  42. Hello there! This post couldn’t be written much better! Looking through this article reminds me of my previous roommate! He continually kept preaching about this. I most certainly will send this post to him. Pretty sure he’ll have a great read. I appreciate you for sharing!

  43. tektok说道:

    It’s an amazing paragraph in support of all the internet users; they will take advantage from it I am sure.

  44. I was able to find good information from your blog articles.

  45. winning303说道:

    Thanks for sharing your thoughts on c/c++. Regards

  46. TEKTK77说道:

    I’m amazed, I must say. Seldom do I encounter a blog that’s both
    equally educative and amusing, and let me tell
    you, you’ve hit the nail on the head. The issue is something
    which too few folks are speaking intelligently about.
    I am very happy that I came across this during my search for something concerning
    this.

  47. slot bank bpd说道:

    Hello there! This post couldn’t be written any better!
    Going through this article reminds me of my previous roommate!
    He continually kept talking about this. I’ll forward this information to him.
    Fairly certain he’s going to have a very good read. Thank you
    for sharing!

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注