c++打印环境变量

直接上代码:cpp版本

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 
 5 extern char** environ;
 6 int main(int argc, char* argv[])
 7 {
 8     printf("Content type:text/plain

");
 9 
10     char** env = environ;
11     while(*env){
12         printf("===%s====
", *env);
13         env++;
14     }   
15     printf("===end=====");
16     fflush(stdout);
17 
18     return 0;
19 }

py版本:

1 #!/usr/bin/python 
2 #encoding=utf-8
3 
4 import os
5 
6 print "Content-type:text/html

"
7 print "<font size=+1>Environment</font>"
8 for param in os.environ.keys():
9     print "<b>%20s</b>: %s "  %(param, os.environ[param])

  c++版本中,上述示例中,需要后续解析字符串,此外使用getenv(varname)获取指定的环境变量值,前提是知道某个环境变量名(key);

原文地址:https://www.cnblogs.com/chris-cp/p/5121194.html