summaryrefslogtreecommitdiffhomepage
path: root/c++.html.markdown
diff options
context:
space:
mode:
Diffstat (limited to 'c++.html.markdown')
-rw-r--r--c++.html.markdown32
1 files changed, 16 insertions, 16 deletions
diff --git a/c++.html.markdown b/c++.html.markdown
index 1461c93e..8d1c7a26 100644
--- a/c++.html.markdown
+++ b/c++.html.markdown
@@ -8,7 +8,6 @@ contributors:
- ["Connor Waters", "http://github.com/connorwaters"]
- ["Ankush Goyal", "http://github.com/ankushg07"]
- ["Jatin Dhankhar", "https://github.com/jatindhankhar"]
-lang: en
---
C++ is a systems programming language that,
@@ -474,6 +473,7 @@ int main() {
// without a public or protected method for doing so
class OwnedDog : public Dog {
+public:
void setOwner(const std::string& dogsOwner);
// Override the behavior of the print function for all OwnedDogs. See
@@ -1000,24 +1000,24 @@ cout << get<5>(concatenated_tuple) << "\n"; // prints: 'A'
// Vector (Dynamic array)
// Allow us to Define the Array or list of objects at run time
-#include<vector>
-vector<Data_Type> Vector_name; // used to initialize the vector
+#include <vector>
+string val;
+vector<string> my_vector; // initialize the vector
cin >> val;
-Vector_name.push_back(val); // will push the value of variable into array
-
-// To iterate through vector, we have 2 choices:
-// Normal looping
-for(int i=0; i<Vector_name.size(); i++)
-// It will iterate through the vector from index '0' till last index
-
-// Iterator
-vector<Data_Type>::iterator it; // initialize the iterator for vector
-for(it=vector_name.begin(); it!=vector_name.end();++it)
+my_vector.push_back(val); // will push the value of 'val' into vector ("array") my_vector
+my_vector.push_back(val); // will push the value into the vector again (now having two elements)
-// For accessing the element of the vector
-// Operator []
-var = vector_name[index]; // Will assign value at that index to var
+// To iterate through a vector we have 2 choices:
+// Either classic looping (iterating through the vector from index 0 to its last index):
+for (int i = 0; i < my_vector.size(); i++) {
+ cout << my_vector[i] << endl; // for accessing a vector's element we can use the operator []
+}
+// or using an iterator:
+vector<string>::iterator it; // initialize the iterator for vector
+for (it = my_vector.begin(); it != my_vector.end(); ++it) {
+ cout << *it << endl;
+}
// Set
// Sets are containers that store unique elements following a specific order.