Learn C++ With Me #18 - Vectors

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 มิ.ย. 2024
  • Welcome back to another C++ tutorial! In this video, we're going over vectors. Vectors are resizeable arrays that are able to change their size based off of what is inside them.
    💻 AlgoExpert is the coding interview prep platform that I used to ace my Microsoft and Shopify interviews. Check it out and get a discount on the platform using the code "techwithtim" algoexpert.io/techwithtim
    🔍 Playlist: • Learn C++ With Me
    ⭐️ Timestamps ⭐️
    00:00 | Introduction
    00:37 | What Are Vectors?
    01:54 | Creating Vectors
    02:24 | Access Vector Elements
    03:12 | Common Vector Methods and Capacity
    08:21 | Insert and Erase Elements
    10:49 | Iterating Through Vectors
    ◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
    💰 Courses & Merch 💰
    💻 The Fundamentals of Programming w/ Python: tech-with-tim.teachable.com/p...
    👕 Merchandise: teespring.com/stores/tech-wit...
    🔗 Social Medias 🔗
    📸 Instagram: / tech_with_tim
    📱 Twitter: / techwithtimm
    ⭐ Discord: / discord
    📝 LinkedIn: / tim-ruscica-82631b179
    🌎 Website: techwithtim.net
    📂 GitHub: github.com/techwithtim
    🔊 Podcast: anchor.fm/tech-with-tim
    🎬 My TH-cam Gear 🎬
    🎥 Main Camera (EOS Canon 90D): amzn.to/3cY23y9
    🎥 Secondary Camera (Panasonic Lumix G7): amzn.to/3fl2iEV
    📹 Main Lens (EFS 24mm f/2.8): amzn.to/2Yuol5r
    🕹 Tripod: amzn.to/3hpSprv
    🎤 Main Microphone (Rode NT1): amzn.to/2HrZxXc
    🎤 Secondary Microphone (Synco Wireless Lapel System): amzn.to/3e07Swl
    🎤 Third Microphone (Rode NTG4+): amzn.to/3oi0v8Z
    ☀️ Lights: amzn.to/2ApeiXr
    ⌨ Keyboard (Daskeyboard 4Q): amzn.to/2YpN5vm
    🖱 Mouse (Logitech MX Master): amzn.to/2HsmRDN
    📸 Webcam (Logitech 1080p Pro): amzn.to/2B2IXcQ
    📢 Speaker (Beats Pill): amzn.to/2XYc5ef
    🎧 Headphones (Bose Quiet Comfort 35): amzn.to/2MWbl3e
    🌞 Lamp (BenQ E-reading Lamp): amzn.to/3e0UCr8
    🌞 Secondary Lamp (BenQ Screenbar Plus): amzn.to/30Dtafi
    💻 Monitor (BenQ EX2780Q): amzn.to/2HsmUPZ
    💻 Monitor (LG Ultrawide 34WN750): amzn.to/3dSD7tS
    🎙 Mic Boom Arm (Rode PSA 1): amzn.to/30EZw9m
    🎚 Audio Interface (Focusrite Scarlet 4i4): amzn.to/2TjXsih
    💸 Donations 💸
    💵 One-Time Donations: www.paypal.com/donate?hosted_...
    💰 Patreon: / techwithtim
    ◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
    ⭐️ Tags ⭐️
    - C++ Tutorial
    - C++
    - Coding Tutorial
    - Tech With Tim
    - Vectors
    ⭐️ Hashtags ⭐️
    #TechWithTim #C++Programming

ความคิดเห็น • 95

  • @lukaslescinskas4844
    @lukaslescinskas4844 3 ปีที่แล้ว +60

    Thank you so much, Tim! This C++ study is the best series from this channel, at least for me. Also more basics of ... could I say, a computer science, would be awesome.

    • @vylcheras7052
      @vylcheras7052 2 ปีที่แล้ว

      🇱🇹🇱🇹🇱🇹🇱🇹🇱🇹

  • @gilberthangshing7427
    @gilberthangshing7427 3 ปีที่แล้ว +5

    Thank you so much tim for this tutorial. I was just thinking about learning vectors and this video pops up. Could really use this in memory hacking.

  • @shamaeelahmed3561
    @shamaeelahmed3561 2 ปีที่แล้ว +24

    Could you please continue this series. Your way of teaching is truly amazing

  • @minemoi7307
    @minemoi7307 2 ปีที่แล้ว +5

    man i was so stuck in a homework and you made me see the light, thank you so much

  • @abrarmasumabir3809
    @abrarmasumabir3809 3 ปีที่แล้ว +3

    bro waiting for 21 C++ tutorial ...bring it alive man...you are my hope :)

  • @stopbysometimes7590
    @stopbysometimes7590 3 ปีที่แล้ว +15

    Hi Tim! Thank you for the vids! I'm a student and its so hard to learn at home but you're making it better for us. Thank you! :D

    • @victor20214
      @victor20214 3 ปีที่แล้ว +1

      Tim inspired me to learn and teach coding. And I started my own thanks

    • @zombiekiller7101
      @zombiekiller7101 3 ปีที่แล้ว

      But no one will see your programming tutorial when there are youtubers like Tech with Tim who provide high quality content.

    • @victor20214
      @victor20214 3 ปีที่แล้ว +2

      @@zombiekiller7101 remember when Tim started there were other great youtubers, before I believe I will be able I just believe

  • @igoorsimoess
    @igoorsimoess 2 ปีที่แล้ว

    Perfect as always
    Thanks, Tim.

  • @MrMShady
    @MrMShady ปีที่แล้ว +4

    3rd method to iterate throught vector:
    for (auto num : v1)
    cout

  • @_alfie_phillips_2058
    @_alfie_phillips_2058 3 ปีที่แล้ว +37

    I love vectors

  • @torishi82
    @torishi82 หลายเดือนก่อน

    Good summary, short and sweet. Thanks.

  • @ritchielrez1680
    @ritchielrez1680 3 ปีที่แล้ว +4

    I thought you only make python tutorials, but now this!!

  • @ketansonar8299
    @ketansonar8299 3 ปีที่แล้ว +1

    You could use short hand for loop to iterate over collections

  • @user-zx1hd6ne2u
    @user-zx1hd6ne2u 2 หลายเดือนก่อน

    simple and useful. great. thank you!

  • @luzgord
    @luzgord 2 ปีที่แล้ว

    Thank you, very helpful!

  • @chadjaasofiane4943
    @chadjaasofiane4943 2 ปีที่แล้ว +1

    really helpful, thank you.

  • @almirf3729
    @almirf3729 ปีที่แล้ว

    Awesome explanation, thanks

  • @souljarohill8795
    @souljarohill8795 ปีที่แล้ว +13

    Vectors are important. I brushed passed it in CS 2 cause i was so focussed on pointers and still am cause pointers are a beast lol. However, its something I'm taking more time in and learning because the fact is when you do a lot of these hackerank assessments or leetcode problems. Vectors are what you need to know to solve the problems. I was so confused when first trying some problems because I had the right mindset but an array wont cut it. Its as you said, regular arrays are good for when you know what you need. it has to have a static and constant size. Which is good in theory for a lot of problems but the problem is there a lot it isnt good enough as well

  • @theblock9221
    @theblock9221 10 หลายเดือนก่อน

    Very useful thank you very much you explained it really well

  • @powerfulLVE
    @powerfulLVE 2 ปีที่แล้ว

    Thanks Tim!

  • @giladsivan3735
    @giladsivan3735 ปีที่แล้ว

    Great Vid, Thanks!

  • @dususbakahyahskahwbwm9113
    @dususbakahyahskahwbwm9113 19 วันที่ผ่านมา

    Hey Tim, your videos have been a great help! Thank you. I seen that during the vid you were looking at your notes to ensure which functions to utilize for the code. Would you mind sharing the source of the information you use for your code and your c++ tutorials in general?

  • @divijagarwal8594
    @divijagarwal8594 3 ปีที่แล้ว +21

    We can insert a value in a vector directly by knowing its index. Like for a vector v1 -> v1[0] = 2;

    • @divijagarwal8594
      @divijagarwal8594 3 ปีที่แล้ว

      @Peterolen oh ok, Thanks for telling :)

    • @justin-ju4eo
      @justin-ju4eo 2 ปีที่แล้ว

      @@DRKongo-vi8ok i think he was replying to someone that deleted their comment

    • @shreyas_._
      @shreyas_._ 2 ปีที่แล้ว

      @@justin-ju4eo you should watch the full video

    • @Musava
      @Musava 2 ปีที่แล้ว +9

      That overrides what is currently there, doesn't insert it into that position?

    • @hitthatrwnoflare9645
      @hitthatrwnoflare9645 ปีที่แล้ว +1

      that wouldn't be an insertion, it would be replacing what is currently at v1[0]

  • @emodat08
    @emodat08 3 ปีที่แล้ว +9

    You are awesome Tim but could you do an algorithms C++ series after this.

  • @jibinvarghese3066
    @jibinvarghese3066 8 หลายเดือนก่อน +1

    A different method to insert:
    int main()
    {
    std::vector v1 = { 1, 2, 3, 4 };
    std::vector::iterator it = v1.begin();
    std::advance(it, 2);
    v1.insert(it, 5);
    std::cout

    • @1-__ISA__-1
      @1-__ISA__-1 17 วันที่ผ่านมา

      Thank you so much!

  • @LorenzotheEngineer
    @LorenzotheEngineer ปีที่แล้ว

    thank you!

  • @muhammadismailcareertips3158
    @muhammadismailcareertips3158 3 ปีที่แล้ว

    great video tips

  • @harshdevmurari007
    @harshdevmurari007 11 หลายเดือนก่อน

    great one...

  • @hitthatrwnoflare9645
    @hitthatrwnoflare9645 ปีที่แล้ว +3

    you can also iterate through a vector using, for example:
    for(int i : [vector name]) {}
    this will iterate through the vector, and will automatically assign i the value at the place in the vector

  • @ericcartman1168
    @ericcartman1168 2 ปีที่แล้ว

    So what's the difference between vector x(size) and int *x = new int[size]. If you where you where to only set the amount of space needed once and not change it both would essentially do the same but is one better?

    • @El-Reyo
      @El-Reyo 10 หลายเดือนก่อน

      they are basically the same but just dynamic arrays use built in language feature but vectors are a separate library or a class that is made with c++ with some functions that makes life easier so you don't have to reinvent the wheel every time.

  • @trithanh9967
    @trithanh9967 8 หลายเดือนก่อน

    thank a lot

  • @kwombat5306
    @kwombat5306 2 ปีที่แล้ว

    do you need to use encapsulation on vectors if they are in class?

  • @zaidzaido4428
    @zaidzaido4428 3 ปีที่แล้ว

    Hello Tim, I have a question.
    How long does it take to me after I learned kotlin to program a dating app with it?

  • @xx_xxx_xxx_xx
    @xx_xxx_xxx_xx 2 ปีที่แล้ว +1

    10:11
    maybe v1.insert(*(v1),5);
    since the pointer of the *array* starts at the first element address

  • @mikmik3965
    @mikmik3965 4 หลายเดือนก่อน

    you can offset the v1.begin() +( actual place you want insert ) like this :v1.insert(v1.begin()+5,1111));

  • @techwithdipufrom0ton621
    @techwithdipufrom0ton621 8 หลายเดือนก่อน

    So here you discuss about the one dimensional array of vectors right? But I wonder if there're any two dimensional vector arrays.

  • @sparshsinghal9238
    @sparshsinghal9238 3 ปีที่แล้ว

    bro how do you know so many things and able to make videos on each. So you must have a good understanding of these.

  • @bullymaguire2335
    @bullymaguire2335 ปีที่แล้ว +1

    what text editor is tim using in this vid

  • @jensbennedsen8575
    @jensbennedsen8575 ปีที่แล้ว

    v1[2] = 6; to assign a (new) value to index 2 of v1

  • @hananissa584
    @hananissa584 2 ปีที่แล้ว +1

    how can we sort vector and print it??

  • @jacobyaacubov8752
    @jacobyaacubov8752 ปีที่แล้ว

    Hi great vid👍, what kind of IDE you use for C++ in this video?

    • @eduato_yt
      @eduato_yt ปีที่แล้ว +1

      I think its sublime text

  • @marekkamyk5518
    @marekkamyk5518 ปีที่แล้ว +1

    Does v1.insert(v1.at(0), 5) would work?

  • @memeph
    @memeph ปีที่แล้ว

    What code editor you're using?

  • @ykzzy4876
    @ykzzy4876 ปีที่แล้ว

    What does the auto iteration
    Is it another way of iterating through a vector.

  • @amanuelfessehaye492
    @amanuelfessehaye492 ปีที่แล้ว

    Txs Tim. but what tool do you use that compile in 8s. very fast. can you send me

  • @dienau6313
    @dienau6313 ปีที่แล้ว +1

    if I type vector v1, what does it mean?

    • @abdul0mar
      @abdul0mar ปีที่แล้ว

      makes a 2d vector
      ex: v1={{1, 2}, {2, 3}}

  • @pythoncure6755
    @pythoncure6755 3 ปีที่แล้ว

    C++ should be having a standard linear algebra module

  • @ruscyber9765
    @ruscyber9765 2 ปีที่แล้ว

    So basically I can use vector instead of static array, cool

  • @mba2ceo
    @mba2ceo ปีที่แล้ว

    How is the MEMORY physically modified ? What is being done under the hood ?

  • @thecodingyoungster
    @thecodingyoungster 3 ปีที่แล้ว

    When is part 2 comming out for typibg race clone?

  • @catcoon3746
    @catcoon3746 ปีที่แล้ว

    [Error] in C++98 'my_vector' must be initialized by constructor, not by '{...}'

  • @tanhnguyen2025
    @tanhnguyen2025 10 หลายเดือนก่อน

    I have several questions that needs answering:
    1) I dont understand the part where inside the for loop that iterates through the vector container, you define the auto itr = v1.begin() and when you ran the program, the compiler error popped up and you said you had to dereference the pointer. How do u know it is a pointer ?
    2) can I apply this method of insert and erase function in C++98? or do i need to update it to the latest version of C++ ?
    Overall, your C++ tutorial video is incredibly amazing and I really appreciate the amount of effort you've put into making this video. Thank you dude !

  • @joshuadodo3488
    @joshuadodo3488 2 หลายเดือนก่อน

    What ide are you using please?

  • @libModz
    @libModz 10 หลายเดือนก่อน

    How do you convert an int vector to void*

  • @farhanjatt6028
    @farhanjatt6028 3 ปีที่แล้ว

    Can you start a tutorial on ethical hacking

  • @tiencongnguyen3668
    @tiencongnguyen3668 2 ปีที่แล้ว

    what is your IDE?

  • @zakariyeisxaaq5839
    @zakariyeisxaaq5839 3 ปีที่แล้ว

    How this guy knows so many programming languages 🤔

  • @karam3045
    @karam3045 3 ปีที่แล้ว +1

    Hey tim, will you ever learn quantum computing languages?

    • @zigzag6111
      @zigzag6111 3 ปีที่แล้ว

      Oh wow did ur clg teach that to u?

  • @techbhanucomputer4389
    @techbhanucomputer4389 3 ปีที่แล้ว

    3rd commenter and 40th viewer

  • @kamil8263
    @kamil8263 2 ปีที่แล้ว

    Capacity is only increasing. The same as taxes...

  • @DreaminBig
    @DreaminBig 3 ปีที่แล้ว +1

    I can't believe you've built a successful TH-cam channel based on stuf that's easily found on the web lol

    • @Dcookies100
      @Dcookies100 ปีที่แล้ว +5

      some people just want stuff in a video format instead of reading it, not a big deal considering so many channels similar to this exist.
      Even bootcamps that cost thousands of dollars just get their stuff off of the internet :p

  • @hectorflorespauner3404
    @hectorflorespauner3404 3 ปีที่แล้ว

    I do not understand why do you say arrays are inmutable in lenght, I tried to create an array with a defined length from the beggining not letting the array to be undefined in lenght and it perfectly lets you add however items you want...

  • @MakerSL
    @MakerSL 2 ปีที่แล้ว

    Thank you so much,

  • @joeboehaha
    @joeboehaha 3 หลายเดือนก่อน

    This dude have very less subscriber feeling bad 😢

  • @clashersamir1625
    @clashersamir1625 5 หลายเดือนก่อน

    bruh just uploaded video on yt without any preparation after getting out from washroom...and still getting views.

  • @Victurf
    @Victurf 2 ปีที่แล้ว

    Hello, for a non-English speaker, you speak too quickly. However, the content is perfect!

    • @Tarou9000
      @Tarou9000 ปีที่แล้ว

      Skill issue

  • @LorenzotheEngineer
    @LorenzotheEngineer ปีที่แล้ว

    :)

  • @johnchu869
    @johnchu869 ปีที่แล้ว

    mark

  • @lokeshwaran9884
    @lokeshwaran9884 3 ปีที่แล้ว +1

    🔥🔥🔥🔥🔥🔥🔥Can h please make the code on VS Code please 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🎉🔥🔥🔥🔥🔥🎉

  • @UserpingSky
    @UserpingSky 2 ปีที่แล้ว

    In the beginning I don’t understand why the output was 16 I understand the output 9 but not 16 where did the 16 come from

    • @sudharshanvasu3121
      @sudharshanvasu3121 2 ปีที่แล้ว

      In vector, the capacity will double if a new element is added. so first, after the capacity exceeds 4, it becomes 8. And when he added more values, when the capacity exceeds 8 it'll just get doubled. So it is 16!

  • @jhonlopez27
    @jhonlopez27 2 ปีที่แล้ว

    I didn't understand nothing about this lesson

  • @benjaminhutz2405
    @benjaminhutz2405 ปีที่แล้ว

    you shouldn't teach people to use namespace std... especially not in tutorials for beginners. Using this namespace is one of the most common sources for errors and bugs and its so easy to avoid