Be aware that if you run a program normally in a shell (terminal window) on your Pi or via Putty or whatever then that program dies when you close that shell session, disconnect putty or whatever.
To have it run forever you could:
1) Run it from the nohup command:
https://linux.101hacks.com/unix/nohup-command/ In which case it's output will go to some file that you can read when you log in again.
2) Run it as a 'daemon', a background service: Typically done by creating a systemd 'service' file for it:
https://domoticproject.com/creating-ras ... %20running. In which case it's output will go to /var/log/syslog or some other log file if you configure it.
3) Run it from screen or tmux as stated above. Basically they run a shell forever, that you can disconnect from without it dying, and you can reconnect to it later.
4) Why send all your programs data to the terminal on standard output. Typically I have such services that should run forever sending their data to an MQTT server, in the cloud or a local machine or even the same Pi, or some other messaging system. That server can then store the data for inspection later in files or a database. It can relay the data in real time to other machines if needed.
Memory in C++ is a leaky abstraction .