This is a very basic set of examples for using c++. Start at "main.cpp" - everything else is called from there.
- Two most common free compilers (probably already installed)
- sudo apt install g++
- sudo apt install clang++
- Install homebrew
- brew install g++
- NOTE: For some reason, on mac, 'g++' is actually an alias for clang++. So, if you want to actually use g++ and not clang++, you need to point to the specific (e.g., g++ => g++-9)
- With windows 10, the easiest way is to install 'windows subsystem for linux'
- Enable 'windows subsystem for linux' under "Turn Windows Features on and off" - then restart your pc
- Using the windows app store, install ubuntu
- You will get a linux bash terminal that runs natively inside windows (not a virtual machine)
- Your windows filesystem can be accessed from inside bash at /mnt/c/ (be very careful - there is no recycle bin, 'rm' is for life)
- You cannot access the ubuntu filesystem from windows except through the terminal
- Then, everything goes as it did for ubuntu
- Two ways to compile.
- Use Makefile. Once make is installed (sudo apt install make)
- Simply run 'make' from command line
- Alternatively: use old style:
- g++ -std=c++11 main.cpp functions.cpp otherFunctions.cpp classExample.cpp VectorArraySTL.cpp random.cpp -o main
- clang++ -std=c++11 main.cpp functions.cpp otherFunctions.cpp classExample.cpp VectorArraySTL.cpp random.cpp -o main
- Then: run the executable: ./main
-
- Highly recommended - large array of tutorials, explainers, cheat sheets etc.
- Start with: https://hackingcpp.com/cpp/beginners_guide.html
-
- Good, lots of examples, beginner friendly
-
- The standard resource, extremely thorough and detailed. Not very beginner-friendly however (reads like a maths textbook)