std sort function in C++

https://youtu.be/nq_8aNhxfTs #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { vector<int> v1 = {1, 6, 2, 5, 10, 4, 11, 3}; sort(v1.begin(), v1.end(), greater<int>()); for (auto el…

std map in C++

https://youtu.be/79s8gkLF6Y8 #include <iostream> #include <map> using namespace std; int main() { map<int, char> m = {{1, 'A'}, {2, 'B'}, {3, 'C'}}; for (auto el : m) { cout << el.first…

std::vector in C++

#include <iostream> #include <vector> using namespace std; int main() { vector<int> v = {4, 5, 6}; v.push_back(7); cout << v[0] << endl; cout << v[3] << endl; cout << "The…

String Streams in C++

https://youtu.be/6WIevcEVBqY?si=xM945G9koO3GoEe3 #include <iostream> #include <sstream> #include <string> using namespace std; int main() { stringstream sStream{"Hello World!"}; cout << sStream.str() << endl; stringstream ss; ss << "Hi There"; cout << ss.str()…

File Streams in C++ read from a file and Write to a file

https://youtu.be/WiZW58Hzt9A?si=BMVrM0xJLcX-k-Sm #include <iostream> #include <fstream> #include <string> using namespace std; int main() { fstream fStream{"read.txt"}; string line; while (fStream) { getline(fStream, line); cout << line << endl; } fstream f{"read.txt"};…

Exceptions in C++

https://youtu.be/ElTUlUHgUi8?si=YqGj4VAfyPaRssBm #include <iostream> #include <memory> using namespace std; int main() { try { int i = 50; throw i; } catch (int ex) { cout << "An integer exception :…

Shared Pointer in C++

https://youtu.be/EYPQxG_0O_k #include <iostream> #include <memory> using namespace std; int main() { shared_ptr<int> ptr1 = make_shared<int>(900); shared_ptr<int> ptr2 = ptr1; shared_ptr<int> ptr3 = ptr1; cout << "Shared pointer 1 : "…

Unique Pointer in C++

https://youtu.be/3qhjScgG4Ho #include <iostream> #include <memory> using namespace std; class MyClass { public: void printMessage() { cout << "Hello World!" << endl; } }; int main() { unique_ptr<int> ptr(new int{500}); cout…

Class Templates in C++

https://youtu.be/qKggWygB1Gc #include <iostream> using namespace std; template <typename T> class MyClass { private: T i; public: MyClass(T ii) : i{ii} { } T retValue() { return i; } }; int…

Function Templates in C++

https://youtu.be/UtJGAD1pOsg #include <iostream> using namespace std; template <typename T> void ourFunction(T p) { cout << "Value is : " << p << endl; } int main() { ourFunction<int>(45); ourFunction<double>(79.40); ourFunction<char>('H');…