Enumerate environment variables in C ++ (cross-platform)

Just a quick question, and I hope this has not been asked before. I want to know a way to list all the assigned environment variables for a process. I need it to be cross-platform for Windows and UNIX-like operating systems.

I know getenv(), but that only returns the value of the variable. I need to create a list of them.

Thank you for your help!

+3
source share
2 answers

Looks like you're just looking for the third argument to main, char ** of the process variables.

Here ya go: main function

The prototype for this form is int main(int argc,char** argv,char** env)

+4
source

Perhaps you are looking for a global variable environ.

0

All Articles