-5

I am writing a short program that displays the argument count (argc), argument vector(argv[]), and environment vector. However, I am unsure how to display the "environment vector" or what it is.

user2891051
  • 37
  • 3
  • 9
  • 1
    Possible duplicate: http://stackoverflow.com/questions/3024197/what-does-int-argc-char-argv-mean – Ilya Aug 25 '14 at 06:24
  • 2
    I've been using C++ since about the time it was invented, and I've never heard of the environment vector. If this is a school assignment (and I don't see how it could be anything else) you should consult your notes/textbook/instructor. – Beta Aug 25 '14 at 06:31
  • 4
    I suspect (confirmation needed) that this refers to an extension: `int main(int argc, char** argv, char** envp);` – MSalters Aug 25 '14 at 06:34
  • 1
    Your title does not correspond to your question – Quest Aug 25 '14 at 06:37

1 Answers1

1

The "environment" parameter, traditionally named envp, is a zero-terminated array of char*.

You can display it like this:

int main(int argc, char* argv[], char* envp[]) 
{
    while (*envp)
    {
        std::cout << *envp << std::endl;
        envp++;
    }
}

It's not part of POSIX (or any other standard) but supported by many compilers.

molbdnilo
  • 64,751
  • 3
  • 43
  • 82