FIND YOUR NEXT FEW LINES

The snippet library.

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

25 snippets foundClear filters
C++Getting Started

Name a value that stays fixed

C++: Use a constant declaration or the language’s constant naming convention for a fixed limit.

C++✓ Tested
C++Getting Started

Print a number with two decimal places

C++: Format a small decimal value consistently for display.

C++✓ Tested
C++Getting Started

Read one character from ASCII text

C++: Use a valid zero-based index to read the first character.

C++✓ Tested
C++Getting Started

Read the beginning of a text value

C++: Extract or display the first three ASCII characters from a known nonempty string.

C++✓ Tested
C++Getting Started

Read the first collection element

C++: Access index zero only after establishing that the collection is nonempty.

C++✓ Tested
C++Getting Started

Repeat a fixed number of times

C++: Use a counted loop to print three numbered steps.

C++✓ Tested
C++Getting Started

Repeat while a condition holds

C++: Count down while a positive number remains, updating the loop variable on each iteration.

C++✓ Tested
C++Getting Started

Replace one collection element

C++: Update an existing element at a known valid index.

C++✓ Tested
C++Getting Started

Require two conditions to be true

C++: Combine a lower and an upper bound to check whether a value is in range.

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++Getting Started

Store a value in a named variable

C++: Give a value a descriptive name and print it.

C++✓ Tested
C++Getting Started

Update a running count

C++: Change a variable after its initial value has been assigned.

C++✓ Tested