FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

125 snippets foundClear filters
C++Tasks & synchronization

Run a task on a thread and join it

C++: Join before reading a result written by the worker thread.

C++✓ Tested
C++Ownership & optional values

Run cleanup through a scoped destructor

C++: A stack object’s destructor runs when its scope exits, including normal exception unwinding.

C++✓ Tested
C++Getting Started

Run your first program

C++: Start with a complete program that prints one line. Follow the run instructions below.

C++✓ Tested
C++Numbers & algorithms

Search a sorted vector

Use binary_search after ensuring C++ values are sorted.

C++✓ Tested
C++Filesystem operations

Set owner-only read and write permissions

C++: Replace ordinary permission bits with the requested owner permissions.

C++✓ Tested
C++Ownership & optional values

Share ownership with a counted smart pointer

C++: Copies of shared_ptr keep the owned value alive until the last owner is released.

C++✓ Tested
C++Collections

Sort a vector

Sort C++ integer values in ascending order.

C++✓ Tested
C++Collections

Sort and deduplicate values

Sort a C++ vector and erase adjacent duplicates.

C++✓ Tested
C++Ordering & set operations

Sort only the smallest requested prefix

C++: partial_sort orders the selected prefix without guaranteeing the order of the remainder.

C++✓ Tested
C++Ordering & set operations

Sort records by two fields

C++: Tuple comparison implements lexicographic ordering across several keys.

C++✓ Tested
C++Strings

Split comma-separated text

Use getline with a delimiter to split simple C++ text.

C++✓ Tested
C++Ownership & optional values

Store a reference in a standard container

C++: reference_wrapper preserves reference semantics while behaving like a copyable container element.

C++✓ Tested