If you don't know what debugging means and how to use a debugger then start learning about about it with highest priority. If you are working on windows then use
Visual Studio[
^] as your IDE (the linked express version is free) - its the best C++ dev env on Earth in my opinion with a superb code editor and debugger integrated together. If you are on linux then I recommend using
Code::Blocks[
^] as your IDE - this one is a very good, free, opensource, multiplatform software supporting many compilers on many platforms (including gcc).
Install one of the previous IDEs and search for a debugging tutorial for the IDE of your choice. In order to be able to choose a good tutorial I describe in a nutshell the most useful things involved in debugging:
You use the debugger by marking some of the code lines with so called "breakpoints" before starting your program. If the execution of your program runs on one of these breakpoints or a fatal error happens (crash) then the debugger suspends the executions of your program and allows you to inspect/modify the state of your program/variables.
The most important views when checking out things:
- Call stack: shows the stack of function calls you are executing on the current thread
- watch/autos view/tooltip: helps you to read/modify the value of global/local/member variables
When you are done with checking out the state of your program you can issue the following operations:
- continue program execution until another breakpoint is hit.
- you can tell the debugger to execute a "single line of code" by entering functions (step in) or without entering them (step over)
Other hints:
- A good debugger allows you to pause program execution at any time but this is not very useful, usually you want to stop only at specific points marked with breakpoints.
- In a good debugger you are allowed to place breakpoints anytime but this is usually (and practically) done before starting the debugged application or when the application is suspended because of hitting a breakpoint.
Many people are lazy to discover the unknown like the usage of a debugger. Its a pity that I have used neither an IDE nor a debugger in the first 1-2 years of my (assembly) programming journey (because I didn't know that such thing exists). Using an IDE and a debugger shortens your learning curve radically, helps in understanding whats goin on inside a running program/process, and you don't have to go to forums to ask people to debug out the reason of your simple/obvious crashes. Finding the reason for a crash if often impossible without a debugger while the same crash is often very-very easy to catch using a debugger.
Your next steps to take: Install and setup/befriend one of the IDEs I've mentioned and then learn how to debug in it.