Skip to content
On this page

C++

Version

Running C++ on C++ v17

Supported languages

C++

Testing framework

catch2

Special reminders and implementation details

cpp
#include <catch2/catch_test_macros.hpp>
#include <iostream>
#include "app.hpp"
using namespace std;

TEST_CASE("Should return Hello World!") {
    REQUIRE(getHelloWorld() == "Hello, World!");
}
1
2
3
4
5
6
7
8

Included libraries

How to debug

Debugging C++ code is crucial for every developer. One of the simplest yet effective ways to debug is by using std::cout statements.

Steps to Debug Using std::cout Statements

  1. Identify the Problem Area: Locate the section of your code where you suspect the problem might be.

  2. Insert std::cout Statements: Add std::cout statements before and after the suspected problematic code to print out variable values and flow control.

  3. Check the Results Output of your tests

  4. Analyze the Output: Look at the values printed on the results console to understand what's going wrong in your code. Adjust your code based on the findings and repeat as necessary.

Example

Here’s an example of how to use std::cout for debugging:

C++ Code

cpp
#include <iostream>

int calculate_sum(int a, int b) {
    std::cout << "calculate_sum called with arguments: " << a << ", " << b << std::endl; // Log function call
    int sum = a + b;
    std::cout << "Sum after addition: " << sum << std::endl; // Log sum calculation
    return sum;
}
1
2
3
4
5
6
7
8