Fixed mistyped words (#25397)

This commit is contained in:
Robert Samu
2018-11-29 14:42:34 +02:00
committed by Aditya
parent 15f51af38b
commit 08cc2e289c

View File

@ -104,13 +104,13 @@ std::string second_item = a[2]; // gets "element"
Looping over elements in a C++ `std::vector` is pretty different from looping over elements in a vector in JavaScript or Ruby. Due to C++ being a thin abstraction of C, you can only loop over elements using these nifty little variables called iterators to access each element.
Iterators often come in the form of pointers which are variables that store the memory address of another variable. You can learn more about pointers [here](https://www.tutorialspoint.com/cplusplus/cpp_pointers.htm).
However, because iterators act as pointers (or vice-versa), in order to see what they point to, you need to dereference it into a variable of the appropirate type.
However, because iterators act as pointers (or vice-versa), in order to see what they point to, you need to dereference it into a variable of the appropriate type.
How do we do this?
HERE. WE. GO!
```cpp
std::vector<std::string> a{"test", "element", "access"};
for(auto it = v.begin(); it != v.end(); it++) { //notice use of auto keyword
cout<<*it<<endl; //Will print out string that the iterator is currently ppointing to
cout<<*it<<endl; //Will print out string that the iterator is currently pointing to
}
```
From here, you can do all sorts of cool stuff, like manipulating the vector or mess around with its order as you please!
@ -234,4 +234,4 @@ int main(){
}
```
You can also sort in descending using lamda like the one above.
You can also sort in descending using lambda like the one above.