C++ Programming Tutorial 51 - Creating a Vector
Vložit
- čas přidán 7. 08. 2024
- Start your software dev career - calcur.tech/dev-fundamentals 💯 FREE Courses (100+ hours) - calcur.tech/all-in-ones
🐍 Python Course - calcur.tech/python-courses
✅ Data Structures & Algorithms - calcur.tech/dsa-youtube
~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~
✉️ Newsletter - calcur.tech/newsletter
📸 Instagram - / calebcurry
🐦 Twitter - / calebcurry
🔗 LinkedIn - / calebcurry
▶️ Subscribe - calcur.tech/subscribe
👨🏻🎓 Courses - www.codebreakthrough.com
~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~
↪ My Amazon Store - www.amazon.com/shop/calebcurry
🅿 Patreon - calcur.tech/patreon-calebcurry
🅖 GitHub Sponsors - github.com/sponsors/CalebCurry
Ⓟ Paypal - paypal.me/calcur
🅑 Bitcoin - 3HnF1SWTzo1dCU7RwFLhgk7SYiVfV37Pbq
🅔 Eth - 0x350139af84b60d075a3a0379716040b63f6D3853
📈 Buy Bitcoin - calcur.tech/crypto
Reserve the Ruby Steel crypto rewards card and get a $25 bonus (use affiliate code "Caleb") - calcur.tech/crypto - Věda a technologie
//simple Fibonacci sequence calculator I made in like 2 minutes. The numbers however overflow at about 20 units.
#include
#include
using std::cin;
using std::cout;
using std::endl;
using std::vector;
int main()
{
vector fib_seq = {1, 1};
cout > units;
for (int i = 1; i < (units - 1); i++)
{
fib_seq.push_back(fib_seq[i - 1] + fib_seq[i]);
}
for (int i = 0; i < units; i++)
{
cout
concise summary! thanks :)
I only code on embedded processors with limited memory. Every library adds up. Im sure it's not an advantage on a phone or a computer, but if your microcontroller only has 16kb ram tightly managing arrays helps keep things concise and manageable.
Hell yea, referencing to outside sources because sometimes you want to encourage self research to play to our curiosity. I see you Caleb, I see you.
Boom, I think you got it!
thanks!!
nice content,
How vectors when passed by reference can remember size inside the function?
I definitely need to try this out for myself. I don’t want to just live vectariously through someone else…
I also use visual studio code. It doesn't allow me to run c++ 11 or 17. How do I fix this?
I'm really having a hard time understanding why used brackets instead of parenthesis for the parameters of the cout. What is the purpose of using the brackets and why does it work?
Not sure what you mean by the "parameters of the cout", but if you mean data[], the brackets are used to tell the index of the data. Parenthesis can't do that.
Here is the link if anyone needs : www.geeksforgeeks.org/vector-in-cpp-stl/
what if i have 1283 elements in the array which equal different numbers for e.g:
1 = 1283
.
.
1283=1681.067
That should work as long as the array is big enough and of the right data type, right?
Im filling an empty array with information from another array with a for loop but im getting an error since there isnt enough allocated memory in the empty array for it to hold all the information. how do i get an empty array to hold all the information?
nvm i figured it out myself.
what is Std:: ?
I think out of all the times you had to use c++11, I only had to use it once. I’m not sure if the fact I’m using a PC makes any difference.
same, I haven't had to use it once and had no errors
@@natecallon9755
The statement vector is a part of C++ 11 is incorrect.
vector is a part of the original C++ STL introduced in 1998.
The intializer list, i.e. the part ' = { 1, 2, 3}' is introduced since C++ 11.
If you create the vector without using the initializer list, say
std::vector v; it compiles fine. You can add values using v.push_back().
💘💘
when i use dev c++, it wont let me type it in the terminal.
you can choose the version off the compiler in devc++ acctually
I am not sure why I cannot learn from your videos.