C++
Learn C++ by typing modern, idiomatic code.
Practice modern C++ by typing it: RAII and smart pointers, templates, move semantics, and STL containers and algorithms. Each snippet is idiomatic C++, and an AI tutor explains every line — why unique_ptr owns and shared_ptr counts, when a move avoids a copy — so the language's power becomes usable while your typing keeps pace.
Progress0 / 690 solved · 0/50 sections
best wpm
0
avg wpm
0
accuracy
0%
runs
0
level
1
rating
1000
Run C++ on your machine
1. Install the toolchain
brew install gcc # or: sudo apt install build-essential2. Save your code as hello.cpp, then compile & run
g++ -std=c++20 hello.cpp -o hello && ./helloprogress by section
1Fundamentals0/15start →
2Strings In Depth0/15start →
3Values & References0/16start →
References are aliasesconst& read-only borrowPointers hold addressesstd::swapPass by value copiesDereference and address-ofMutable referencePointers can be nullBorrow big dataReference vs pointerCopy versus movestd::moveReturn a referenceunique_ptr owns the heapA reference membershared_ptr shares ownership
4Slices & Arrays0/17Unlock →
5Data structures0/13Unlock →
6Iterators0/20Unlock →
7Traits0/20Unlock →
Default membersOperator +Converting constructorConcept-bounded parameterOperator ==std::hash specializationUnary operator -Three-way comparisonOperator +=CRTP clone vs copyDestructor (RAII)Operator * by scalarCustom operator<<Fallible conversionConcept with associated typeDereference operatorsMultidimensional subscriptCustom iteratorRange-for supportBuild from a range
8Generics0/20Unlock →
Class templateA concept constraintA generic sum typeFunction templateTwo type parametersConstrained auto parameterClass template argument deductionBuild a value genericallyMethods on a class templateGeneric min over a rangeCombine conceptsA strong type wrapperA requires clauseTemplate specializationFold with side effectsVariadic template + foldif constexprGeneric with a key functionNon-type template parameterA requires expression
9Lifetimes0/20Unlock →
A string_view subviewLambdas capture by referenceFunction pointers hold no stateReturning a referenceReturning a member referenceString literal storageReference to an elementMethod returning a viewTwo borrowed viewsstd::reference_wrapperA view cannot outlive its ownerA variant that can borrowStruct holding a viewGeneric reference memberA view into a vector elementA mutable reference memberA borrowing parserReference tied to one argumentScope-bound destructionA lazy view borrows its input
10Closures0/20Unlock →
A lambdaCapture by referenceCapture by valueLambda as a template argumentCallbacksInit captureFunction pointersGeneric lambdaLambdas drive rangesMutable lambdasort with a lambda comparatorstd::functionstd::bind_frontCapture by moveCurryingReturning a lambdaA stateful accumulatorTemplate lambdaCompose two callablesA pipeline of std::function
11Pattern Matching0/20Unlock →
switch and defaultif with initializerMatch an optionalGrouped casesRange matchingDestructure a structDestructure a tupleswitch yields a valueMatch an expectedget_ifA guard on a matchholds_alternativeDestructure in a loopMatch strings via a mapswitch with initializerMatch by sizevariant + visitMatch variant shapesMatch on the held typeMatch a recursive variant
12Error Handling0/20Unlock →
Fall back to a defaultstd::runtime_errorthrow and catchCatch anythingCatch by const referenceFallback from the errorstd::invalid_argumentmain reports failurenoexcept functionsoptional for absenceoptional::value throwsCustom exception typestd::exception hierarchyRAII cleans up on throwRethrow with bare throwstd::error_codeCompare against std::errcA scope guardTranslate an exceptionNested exceptions
13Option & Result0/20Unlock →
has_value and bool testExplicit nullopttransform an optionalvalue_or defaultDereference the valuestd::expected valueRead the errorexpected value_orFilter with and_thenor_else fallbackreset to emptytransform then value_orand_then (monadic bind)emplace in placeexpected transformUnwrap in an if-initCollect into optionalexpected and_thenexpected or_elsetransform_error
14Conversions0/15Unlock →
15Collection Conversions0/19Unlock →
Extract map keysExtract map valuesPairs to a mapSet to sorted vectorVector to dequeVector to std::setVector to unordered_setFlatten nested vectorsFrequency countMap keys into a setMap to vector of pairsunordered_map to mapUnique, keeping orderDedupe with sort + uniqueGroup into a mapInvert a mapranges::to a containerTwo vectors to a mapranges::to a map
16Math0/14Unlock →
17Encoding0/22Unlock →
String to bytesASCII checks and caseBytes to StringChar to code pointChar digit valueBinary, octal, hex formattingBig-endian bytesList code pointsEscape a stringHex encodeLittle-endian bytesBytes vs code pointsParse a number in a baseByte swap & endiannessCaesar cipherHex decodePercent-encodeROT13XOR cipherPercent-decodeBase64 decodeBase64 encode
18Random0/20Unlock →
Mersenne Twister engineSeed from the clockCoin flipPick a random elementSeed from random_deviceInteger in a rangeFloat in [0, 1)Random alphanumeric stringWeighted true/falseRandom bytesRandom enum variantPassword generatorRoll in an arbitrary rangeReproducible sequencesShuffle a sequenceRoll many diceNormal distributionSample without replacementWeighted choiceUUID-v4-shaped string
19Data I/O0/18Unlock →
Parse CSV into rowsTab-separated valuesBuild a CSV stringSelect one columnCSV into a number matrixSplit off the headerWhitespace-separated matrixRead a data fileSerialize records to CSVSkip blanks and commentsPrint an aligned tableWrite CSV to a fileWrite a matrix as textAppend a rowStream lines from a fileParse key=value configRound-trip write then readDrop unparseable rows
20Linear Algebra0/21Unlock →
Matrix shapeScalar multiplyA matrix of zerosElementwise addArgmax of a vectorIdentity matrixOne-hot encodeTraceStack rows (vstack)ReLU and sigmoidApply a function elementwiseColumn meansColumn sumsCosine similarityFlat storage, 2D indexingMatrix times vectorTransposeMatrix multiplyMin-max normalize columnsSoftmaxStandardize columns (z-score)
21Text Processing0/16Unlock →
22Date & Time0/12Unlock →
23Memory0/12Unlock →
24Modules0/20Unlock →
A namespaceusing-declarationNamespace aliasConstants in a namespacePublic vs internalAn enum in a namespaceSeveral using-declarationsNested namespaces (C++17)using namespaceGlobal scope pathReach the enclosing scopeSame-namespace callA small utility namespaceA struct in a namespaceAnonymous namespacePrivate field, public getterFlatten a deep pathInline namespace re-exportAn interface in a namespaceReach a sibling namespace
25Macros0/20Unlock →
assert and static_assertWrite to standard errorTwo vector constructionsLiteral join and token pasteAn object-like macroMatch against a setA todo placeholderA dbg-style macrostd::format specifiersA function-like macroThe # stringize operatorVariadic sum with a foldFormat into a stringBuild a vector from a packTemplate specializationCRTP generates methodsBuild a map from pairsPass a callableCount pack elementsRecursive variadic max
26Testing0/20Unlock →
assert with a messageAn expect-not-equal helperA tiny test helperMultiple testsAssert on returned textCover both branchesTest the out-of-bounds pathDoc comment and a compile-time testTest an error resultAssert that code throwsA shared test helperTest a class methodTest an optionalSkip a slow testCompare whole vectorsTest a std::expected resultCompare floats with an epsilonTest internal helpersTable-driven testsCheck the exception message
27Algorithms0/8Unlock →
28Sorting Algorithms0/12Unlock →
29Expression Parsing0/6Unlock →
30Idioms0/9Unlock →
31OOP & Traits0/8Unlock →
32Trait Objects0/14Unlock →
Shared method over a baseTake a const Base&Return unique_ptr<Base>A vector of std::functionFixed type vs base pointerShared base pointerA span of base pointersTemplate vs virtualExtended interface objectA vector of base pointersDowncast with dynamic_castA handler registryClosed set with variantObject holding a view
33Design Patterns0/14Unlock →
35File I/O0/6Unlock →
36Filesystem0/18Unlock →
Does a path exist?Copy a fileCreate nested directoriesFiles vs directoriesBuild a pathList a directoryRename or moveChange the extensionFile metadataPath componentsRemove files and treesSorted listingWrite to the temp dirAbsolute pathFilter by extensionLast modified timeWalk the treeTotal size of a tree
37Networking0/16Unlock →
Parse the request lineRoute by pathClassify an IP addressBuild and read a socket addressBind an ephemeral portResolve a hostnameBuild an HTTP responseRead a line from a socketShut down a connectionTCP client with RAIISet a read timeoutUDP receiveUDP sendTCP echo serverA thread per connectionServe a web page
38Concurrency0/7Unlock →
39Unsafe & FFI0/14Unlock →
40Commands0/14Unlock →
41Array0/10Unlock →
43String0/10Unlock →
45Interval0/5Unlock →
46Linked List0/6Unlock →
47Tree0/14Unlock →
Maximum Depth of Binary TreeInvert Binary TreeSame TreeLowest Common Ancestor of a BSTBinary Tree Level Order TraversalSubtree of Another TreeImplement Trie (Prefix Tree)Kth Smallest Element in a BSTValidate Binary Search TreeAdd and Search WordConstruct Binary Tree from Preorder and InorderBinary Tree Maximum Path SumSerialize and Deserialize Binary TreeWord Search II