so I will save data in a file format called 'rosbags' librealsense/readme.md at master · IntelRealSense/librealsense · GitHub
then Should I use this code
I believe you should use the upper instructions. It looks as though the lower one at src/media/record is the source code that the SDK uses to make recording work.
then after making recording work with the code below, shoud i use upper code?
You should not need to change the lower code at all. The only reason to change it is if you wanted to make your own version of the SDK 2.0 software that makes recording work differently to how it works now. You only need to use the upper code.
Retrieving data ...