Either call Win32 API or some library.
I've tried to call system("set env=1"), defined in <process.h>. But it doesn't work. Seems nothing get added after I tried echo %env%.
I hope this should work:
_putenv("env=1");
or
_tputenv(_T("env=1"));
SetEnvironmentVariableA("env", "1");
SetEnvironmentVariable(_T("env"), _T("1"));