Hello all thanks for adding me to c++ forum.
am newbee to c++ programming I would like to know if der is a command to debug line by line in linux. ex: if i compile the below code g++ -xyz prog.cpp /S
it should compile single line and show the o/p each time i press S.
Please guide me.
You can use gdb. Compile the file with the -g flag and don't turn on optimizations.
g++ -o prog prog.cpp -g
This will compile the program into an executable file named prog.
Run gdb ./prog to start debug prog using gdb. You then write commands to instruct gdb what to do. First you need to start the program by typing start and press enter. Use next to step to the next line. If you want to step into functions you can use step instead. To print local variables you can do info locals. To print the value of a specific variable type print NameOfVariable. To quit gdb you type q.
Note that you can quickly repeat previous commands using the up key and auto complete using the tab key (as in the normal terminal) so you don't have to repeatedly type next, next, ...
If you want to step more than one line at once you can add the number of lines after next or step (e.g. next 5).