Printenv list all environment variable from the command line but failed to list all environment variable from code
As mentioned in the comments, system
creates a child process so the environment variables might be different from the ones existing in your application's environment.
You can use std::genenv
to get environment variables.