C++
Version
Running C++ on C++ v17
Supported languages
C++
Testing framework
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
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
Identify the Problem Area: Locate the section of your code where you suspect the problem might be.
Insert
std::cout
Statements: Addstd::cout
statements before and after the suspected problematic code to print out variable values and flow control.Check the Results Output of your tests
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
2
3
4
5
6
7
8