terminate called after throwing an instance of 'rosbag::BagIOException'

Most likely you are expecting the C++ runtime to resolve/replace the ~ with the path to the users home directory. Afaik that behaviour is implemented by the shell (ie: bash), it's not something that works everywhere.
Can you try to provide an absolute (or even relative) path to rosbag::Bag::open(..)?