💻

Introduction to C++ Programming

Aug 1, 2024

C++ Programming Lecture Notes

Introduction

  • C++ is a fast, middle-level programming language.
    • Commonly used in advanced graphics, embedded systems, and video game development.
    • Sits between high-level languages (closer to human language) and low-level languages (closer to hardware instructions).
  • Learning Curve: C++ can be challenging but rewarding.

Getting Started

Tools Needed

  1. Text Editor: Examples include VS Code, Code::Blocks, or Notepad.
    • VS Code and Code::Blocks are Integrated Development Environments (IDEs) with useful developer tools.
  2. Compiler: Translates source code to machine instructions.
    • GCC for Windows/Linux, Clang for macOS.

Setup Instructions

Download and Install VS Code

  1. Go to code.visualstudio.com and download the appropriate version for your OS.
  2. Run the installer and follow the prompts.
  3. Install extensions: C/C++ and Code Runner.

Download and Install Compiler

  • Linux: gcc -v, sudo apt install build-essential.
  • macOS: clang --version, xcode-select --install.
  • Windows: Install MinGW.
    • Configure environment variables to include the MinGW bin directory.

Writing Your First Program

  1. Create a new folder for your projects.
  2. Create a new file: hello_world.cpp.
  3. Write basic code: #include <iostream> int main() { std::cout << "I like pizza" << std::endl; return 0; }
  4. Compile and run the program using the compiler.

Basic Syntax and Structure

Functions

  • Main Function: Entry point of a C++ program.
  • Include Directives: #include <iostream> for input/output operations.

Comments

  • Single-line: // this is a comment.
  • Multi-line: /* this is a multi-line comment */.

Output

  • Standard Output: std::cout <<