Set local environment variables in C++

How do I set an environment variable in C++?
They do not need to persist past program execution
They only need to be visible in the current process
Preference for platform independent but for my …