C++ / learning · November 14, 2021 0

Test For No Errors!

Remember: in C++, a frequent thing that needs to be done is to test (use debugging code) to check that there are no mistakes. Why? Mistakes could be solved easily, but if there are too many all of them would be hard to solve. Plus, if an entire program was typed out, but it was only checked in the end, and the logic is wrong, the entire time would be wasted. However, if the program was checked in the beginning, there would be less time wasted and less errors in the end.

When finishing the debugging code and knowing there is nothing wrong, you need to remove it. But sometimes you will accidently remove some of your good code. To solve it, put some mark to represent the start and the end of the debugging area.

Example:

#include <iostream>
using namespace std;

int main()
{
    string x;
    cin >> x;
    /*notice that there are slashes to show the start and 
    end of the testing code.*/
    /////
    cout << "x is: " << x << endl;
    /////
}