How to print the elements of a C++ std::vector with GNU Debugger GDB ?
How to print the elements of a C++ std::vector with GNU Debugger GDB ?
Consider the following code {test.cpp}:
Let’s compile with debug flag -g
And Launch gdb with test executable:
We add a breakpoint at line 8 and we launch test executable
To print all elements use
print *(your_vector._M_impl._M_start)@your_vector_size
Here:
To print the two first element:
Finally to print an element:
If you found this post or this website helpful and would like to support our work, please consider making a donation. Thank you!
Help Us