Skip to content

← Orientation and the Gate step 3 of 3

Easy Primitives

What gets compiled with your code

The starter uses std::vector and std::string without including their headers. Add those includes so the function can compile. The supplied harness handles input, output and main for you.

What the runtime compiles

The runtime builds one source file, called a translation unit, in this order:

1. Your submitted code
2. A JSON helper
3. The exercise harness, including main()

Your code comes first, so ordinary diagnostics pointing into it use the same line numbers as your editor. The helper and harness follow your last line.

Include the headers you use

A header included later in the file cannot provide declarations for your earlier function definition. Put #include <vector> and #include <string> before the function.

Some headers include others internally. Do not rely on an incidental include to expose a type: include its own header so your code does not depend on a particular standard-library implementation.

When the error points into the harness

The runtime filters structured diagnostics to your source lines. If compilation fails without an error attributed to those lines, it adds an explanation and an excerpt of the compiler output.

A missing function or incompatible signature can cause this: your declarations may compile, but the harness cannot call them as intended. First compare your function's name, parameter types and return type with the required signature. Then read the compiler excerpt. The fallback message is a troubleshooting hint, not proof that every such failure has the same cause.

Your task

std::vector<std::string> repeat_each(const std::vector<std::string>& words,
                                   int times);

Add the two missing headers. Keep the existing function and algorithm:

  • Append times copies of each string, preserving input order.
  • Repeat each whole string; do not join copies into a single string.
  • Return an empty vector when times <= 0 or words is empty.
  • Preserve empty strings and duplicates like any other input elements.

For words = {"a", "b"} and times = 2, return {"a", "a", "b", "b"}. The harness serializes this vector as the displayed result. It does not require you to print anything or define another main.