C++
open, GitHub.io, 2024
This course is to become familar with C++.
C++
Sr.No | Topics | Slides | |
---|---|---|---|
1 | C++ Introduction: comments; preprocessing directive; whitespace; structure of function; input and output streams; std namespace; escape sequences; initialization; insertion and extraction operator; arithmetic, relational, and logical operator; if statement; input/output manipulators boolalpha and noboolalpha; string class; syntax and logical errors | 2_intro | |
2 | Control Statements: selection statements if, if-else, switch; iteration statements while, do-while, for, range based for; conditional operator; prefix and postfix operators; nested control statements; controlling iterations with counter and sentinel value; using std locale; mixed expression; formatting floating point numbers using iomanip; using super sized integer with boost | 3_control | |
3 | Control Statements: counter-controlled iteration using while and for; text formatting using std format; floating point approximation; representational error; counter controlled do-while; sentinel controlled while with end-of-file; switch-case; break; fallthrough; if with initializer; switch with initializer; break; continue; logical operator; operator precedence; equality and assignment; yoda condition | 4_control | |
4 | Functions: using functions from cmath; defining functions; comma operator; argument coercion; narrow_cast using gsl; generating random numbers; digit separator; scoped enum; using enum; inline functions; passing arguments by value and reference; using const reference; avoiding dangling references; treating warnings as errors; function overloading; name mangling; function templates; recursion; global scope; unary scope resolution operator | 5_functions | |
5 | Arrays, Vectors, Ranges, and Functional-Style Programming: fixed size array and resizable vectors; static array; initialization array; class template argument deduction; range-based for; external and internal iteration; const and constexpr; multi dimensional arrays; programming styles procedural, object oriented, generic, and functional style programming; passing functions as arguments; ranges and views; lazy valuation using std::views::iota; filter and transfom using views; creating pipeline of views; vector; at; exception; iterator; push_back; emplace_back; clear; erase single or range; pop_back | 6_arrays_vectors | |
6 | Pointers | 7_pointers |
Recommended Books/Resources
- C++ How to Program: An Objects-Natural Approach, 11/e by Paul Deitel & Harvey Deitel
- The C++ Programming Language (4th Edition) by Bjarne Stroustrup, Addison-Wesley
C++ Installation
- Cross Platform IDE Editors
- Visual Studio Code, https://code.visualstudio.com/
- Cursor, https://www.cursor.com/
- CLion, https://www.jetbrains.com/clion/
- Mac: Install Xcode from Mac AppSore
- Try g++ –version
- Install CMake and Ctach2 using Homebrew
# install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# install cmake
brew install cmake
# install catch2
brew install catch2
brew install boost
brew --prefix boost # get path
- Windows installation
- Get Catch2 single file [Mac and Windows]
- Adjusting font in VS Code/Cursor
- Find Open Settings: Command + Shift + P> Open Settings
- Find “terminal.integrated.fontSize”: 20
- Find Open Settings: Command + Shift + P> Open Settings
- Settings
{
"editor.fontSize": 24,
"terminal.integrated.fontSize": 24,
"editor.wordWrap": "on",
"workbench.colorTheme": "Default Light Modern"
}
- Set C++ 20 in the VS Code
- Command + Shift + P > C/C++: Edit Configurations (JSON)
"cStandard": "c23",
"cppStandard": "c++23"
- Install GSL: Guidelines Support Library, https://github.com/Microsoft/GSL
- Command + Shift + P > C/C++: Edit Configurations (JSON)
"includePath": [
"${workspaceFolder}/**",
"${env:HOME}/soft/GSL/include",
"/usr/local/opt/boost"
],
- Use the below command to compile
clear && g++ -std=c++20 -I$HOME/soft/GSL/include main.cpp && ./a.out
- Convert C++ Warnings to Errors for safety
clear && g++ -std=c++23 -Werror main.cpp && ./a.out
- check name mangling for overloading
nm a.out
nm a.out | c++filt #c++ nmames