noknow.dev
Sign inSign up
Course overview
C++ Fundamentals
0 / 39 lessons0%

Getting Started

  • Hello, World!
  • Variables and Data Types
  • Arithmetic and Operators
  • Working with std::string
  • Type Conversion and Casting

Control Flow

  • if / else if / else
  • switch / case
  • while and do-while Loops
  • for Loops
  • break, continue, and Finding Primes

Functions

  • Writing Functions
  • Pass by Value vs. Pass by Reference
  • Overloading and Default Parameters
  • Recursion

Arrays and Strings

  • C-style Arrays
  • std::vector — Dynamic Arrays
  • std::string Deep Dive
  • 2D Arrays and Matrices

Pointers and Memory

  • Memory Addresses and Pointers
  • Dynamic Memory: new and delete
  • References vs Pointers

Object-Oriented Programming

  • Classes and Objects
  • Constructors and Destructors
  • Inheritance
  • Virtual Functions and Polymorphism
  • Operator Overloading

The Standard Template Library

  • std::vector in Depth
  • std::map and std::unordered_map
  • std::set and Sorted Unique Collections
  • STL Algorithms

Templates and Generic Programming

  • Function Templates
  • Class Templates

Modern C++ (C++11/14/17)

  • auto and Range-based for
  • Lambda Functions
  • Smart Pointers
  • Move Semantics

Error Handling and Exceptions

  • try / catch / throw
  • Custom Exception Classes
  • RAII and Resource Management

auto and Range-based for

0m 00s

Writing Less, Saying More

auto x = 42;         // int
auto y = 3.14;       // double
auto s = string("hi"); // string

// Especially useful with complex types:
map<string, vector<int>>::iterator it = data.begin(); // old way
auto it = data.begin();                                  // new way!

Range-based for

vector<int> nums = {1,2,3,4,5};

for (int x : nums)          cout << x;   // by value (copy)
for (const int& x : nums)  cout << x;   // by const ref (cheap)
for (int& x : nums)        x *= 2;      // by ref (modifies)

Structured bindings (C++17)

map<string,int> scores = {{"Alice",95},{"Bob",87}};
for (auto& [name, score] : scores) {
    cout << name << ": " << score;
}

Your Task

Write filterPositive(vector<int> v) using range-based for that returns only elements > 0.

Back
cppCtrl+Enter to run
Output

Click "Run" to execute your code.