1、安装gcc/g++/gdb
[root@VM_0_11_centos Program]# yum -y install gcc
[root@VM_0_11_centos Program]# yum -y install gcc-c++
[root@VM_0_11_centos Program]# yum -y install gdb
2、编译源码
[root@VM_0_11_centos Program]# cat test.cpp
#include <iostream>
using namespace std;
int main()
{
int a = 0;
cout<<a<<endl;
for (int i = 0; i < 10; ++i) {
cout<<i<<endl;
}
return 0;
}
[root@VM_0_11_centos Program]#
[root@VM_0_11_centos Program]# g++ -g test.cpp -o test #-g参数是调试参数,这样才能使用gdb调试
[root@VM_0_11_centos Program]# ll
total 24
-rwxr-xr-x 1 root root 19600 Mar 29 08:44 test
-rw-r--r-- 1 root root 149 Mar 29 08:38 test.cpp
[root@VM_0_11_centos Program]#
3、输出代码
l(list)打印源代码,一次只显示10行代码
[root@VM_0_11_cent