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.
Asked
Active
Viewed 592 times
-5
-
1Possible duplicate: http://stackoverflow.com/questions/3024197/what-does-int-argc-char-argv-mean – Ilya Aug 25 '14 at 06:24
-
2I'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
-
4I suspect (confirmation needed) that this refers to an extension: `int main(int argc, char** argv, char** envp);` – MSalters Aug 25 '14 at 06:34
-
1Your title does not correspond to your question – Quest Aug 25 '14 at 06:37
1 Answers
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