C++ typing test
C++ builds templates, namespaces and smart pointers on top of C, and each brings its own symbols. Every program here uses std::, output goes through <<, and the Expert programs use types like std::unique_ptr<Node>. It's one of the most symbol-heavy languages in the test.
What you'll type in C++
std::, a double colon beforecout,make_uniqueand more.<<to send values tostd::cout.< >in templates and in#include <iostream>.&for references, as instd::unique_ptr<Node>& root.->to reach through pointers and!for null checks, as inif (!root).
Example: FizzBuzz in C++
Every output line chains std::cout << with a string. Watch the last else, which needs two << to print the number and then a line break.
#include <iostream>
int main() {
for (int i = 1; i <= 15; i++) {
if (i % 15 == 0) std::cout << "FizzBuzz\n";
else if (i % 3 == 0) std::cout << "Fizz\n";
else if (i % 5 == 0) std::cout << "Buzz\n";
else std::cout << i << "\n";
}
}
Tips for typing C++ faster
- Hold Shift through both colons of
::rather than pressing it twice. - Most slips happen on
<<and::. Slow down on the symbols and let the words around them flow. - Type the same program in C first, then C++, to see how the extra symbols change your time.
All 20 C++ programs
Every program is real, working C++. Choose one to start typing it straight away.
Beginner
- Hello, World!Print a greeting.
- Count to fivePrint the numbers 1 to 5.
- Celsius to FahrenheitConvert 100 °C to Fahrenheit.
- Sum a listAdd up 3, 1, 4, 1, 5.
- Find the largestFind the biggest number in a list.
- Count vowelsCount the vowels in "keyboard".
Intermediate
- Reverse a stringTurn "hello" into "olleh".
- FizzBuzzFizz for 3s, Buzz for 5s, 1 to 15.
- FactorialA recursive function, called with 5.
- FibonacciPrint the first ten Fibonacci numbers.
- Greatest common divisorEuclid's algorithm for 48 and 18.
Advanced
- Primes to 20Print every prime up to 20.
- PalindromeCheck whether "racecar" reads the same backwards.
- Word countCount the words in a sentence.
- Bubble sortSort 5, 2, 9, 1, 7 by swapping neighbours.
- Binary searchFind 7 in a sorted list by halving.
Expert
- QuicksortSort a list by partitioning around a pivot.
- Binary search treeBuild a tree, then read the values back in order.
- Shortest path (BFS)Breadth-first search through a small graph.
- N-QueensCount the ways to place 6 queens so none attack.
How the test works
The timer starts on your first key and stops once every character is right. Press Enter for a new line and the indentation is filled in for you. A wrong key shows in red and counts as a mistake; press Backspace to go back and fix it. Your best time for each program is saved in your browser. Read more about how speed and accuracy are calculated, or get tips for typing code faster.