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\n\n"); 9 10 char** env = environ; 11 while(*env){ 12 printf("===%s====\n", *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\r\n\r\n" 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++版本中,上述示例中,需要后續(xù)解析字符串,此外使用getenv(varname)獲取指定的環(huán)境變量值,前提是知道某個環(huán)境變量名(key);
?
轉(zhuǎn)載于:https://www.cnblogs.com/chris-cp/p/5121194.html
總結(jié)
- 上一篇: 关于烂代码的那些事(上)
- 下一篇: c/c++常见面试题