Why Learn C++?
► It is fast. You will see c++ used frequently in industries like gaming and high frequency trading where speed is critical.
► It has a wonderful feature (the destructor) that allows us to manage resources and guarantee they are released correctly and in a timely manner. This feature is used in a programming technique called RAII (resource acquisition is initialization) and is crucial for industries that require predictability and accuracy such as: finance, real-time and embedded high performance systems.
► C++ is powerful and expressive. You can do a great deal more in a few lines of C++ code that you could in the same amount of C code.
Here's an example showing how some of that power and expressiveness (file: test.cpp):
#include <algorithm> #include <iostream> #include <iomanip> #include <fstream> #include <string> #include <cctype> #include <map> int main() { std::ifstream in("finn.txt"); if(!in) { std::cout << "Could not open file\n"; return(1); } std::map<char, int> letterToCount; for(char c : "abcdefghijklmnopqrstuvwxyz") letterToCount[c] = 0; std::string line; int maxCount = 0; while(getline(in, line)) for(char c : line) if(isalpha(c)) maxCount = std::max(maxCount, ++letterToCount[(char)tolower(c)]); for(int i = maxCount; i > 0; i --) for(auto pair : letterToCount) if(pair.second == i) std::cout << std::setw(3) << i << ": " << pair.first << "\n"; return(0); }
When executed, the above program outputs:
181: t 172: e 147: a 143: o 111: n 107: h 107: i 98: d 81: s 78: l 72: r 62: u 61: w 49: m 40: g 38: b 36: y 31: c 21: f 19: p 14: k 11: v 3: j 2: x 1: z
A list of all letters that occurred in the text file is shown, sorted by frequency (most common to least common).
► As of July, 2021, the TIOBE Index of programming popularity was:
As you can see, c++ is quite popular
► A great deal of the software that we use day-to-day is written in C++ such as:
► ONLINE RESOURCES
► COMPILERS
► TEXTBOOKS