This lesson is still being designed and assembled (Pre-Alpha version)

Code inclusion

Overview

Teaching: 0 min
Exercises: 0 min
Questions
  • How can I include code from an external file in my lesson

Objectives
  • Include external code

Code includes

Might be good for unit testing code snippets and for having syntax highlighting etc. when writing longer bits. Also great when you want to give students the opportunity to download the full files.

This is a full include:

#include <iostream>

int main() {
  std::cout << "hello, world" << std::endl;
  return 0;
}
Get the full file: code/hello.cpp

This is a partial include with line numbers

int main() {
  std::cout << "hello, world" << std::endl;
  return 0;
}
Get the full file: code/hello.cpp

You can also include from a string to a string:

int main() {
  std::cout << "hello, world" << std::endl;
  return 0;
}
Get the full file: code/hello.cpp

Key Points

  • Put your code snippets in _episodes/code/

  • There are three different ways to include code.