diff options
Diffstat (limited to 'c++.html.markdown')
| -rw-r--r-- | c++.html.markdown | 55 | 
1 files changed, 32 insertions, 23 deletions
diff --git a/c++.html.markdown b/c++.html.markdown index 5220fb0b..4113d5f4 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, @@ -72,10 +71,16 @@ void func(); // function which may accept any number of arguments  // Use nullptr instead of NULL in C++  int* ip = nullptr; -// C standard headers are available in C++, -// but are prefixed with "c" and have no .h suffix. +// C standard headers are available in C++. +// C headers end in .h, while  +// C++ headers are prefixed with "c" and have no ".h" suffix. + +// The C++ standard version:  #include <cstdio> +//The C standard version: +#include <stdio.h> +  int main()  {      printf("Hello, world!\n"); @@ -217,7 +222,7 @@ cout << myString + myOtherString; // "Hello World"  cout << myString + " You"; // "Hello You" -// C++ strings are mutable and have value semantics. +// C++ strings are mutable.  myString.append(" Dog");  cout << myString; // "Hello Dog" @@ -474,6 +479,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 +1006,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 +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) -// Iterator -vector<Data_Type>::iterator it; // initialize the iterator for vector -for(it=vector_name.begin(); it!=vector_name.end();++it) - -// 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. @@ -1051,6 +1057,8 @@ cout << ST.size();  // will print the size of set ST  // Output: 0  // NOTE: for duplicate elements we can use multiset +// NOTE: For hash sets, use unordered_set. They are more efficient but  +// do not preserve order. unordered_set is available since C++11  // Map  // Maps store elements formed by a combination of a key value @@ -1078,6 +1086,8 @@ cout << it->second;  // Output: 26 +// NOTE: For hash maps, use unordered_map. They are more efficient but do  +// not preserve order. unordered_map is available since C++11.  ///////////////////////////////////  // Logical and Bitwise operators @@ -1127,7 +1137,6 @@ compl 4    // Performs a bitwise not  ```  Further Reading: -An up-to-date language reference can be found at -<http://cppreference.com/w/cpp> - -Additional resources may be found at <http://cplusplus.com> +* An up-to-date language reference can be found at [CPP Reference](http://cppreference.com/w/cpp). +* Additional resources may be found at [CPlusPlus](http://cplusplus.com). +* A tutorial covering basics of language and setting up coding environment is available at [TheChernoProject - C++](https://www.youtube.com/playlist?list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb).  | 
