用C/C++程序控制环境变量
In C++, how do i go about using setenv to set the display? I need to set it like this:
export DISPLAY=0.0
1、setenv("DISPLAY",":0.1",1);
If you're calling the xrandr functions from your C++ program, then I would expect setenv() should work for you. The 3rd argument of 1 tells setenv() to overwrite any previous value of argument 1 (DISPLAY). You'd be out of luck if xrandr cached the display name though. In that case, you'd have to re-invoke a program from a shell script: the shell script could set the DISPLAY each time before starting your program. That would be less C++ coding
#include <stdlib.h>
#include <stdio.h>
int main(){
char *env1 = getenv("test11");
printf("test11=%s\n", env1); //show current env variable
setenv("test11","abcd",1); //reset it
env1 = getenv("test11");
printf("test11=%s\n", env1);
//this value reset is gone after the program finished
return 0;
}
g++ setenv.cpp -o mysetenv
相关文档:
与 &: 任何位用&运算与0结合结果为0,与1结合结果为其本身;
或 | : 任何位用|运算与0结合结果为其本身,与1结合结果为1;
异或 ^ : 任何位用^运算与0结合结果为其本身,与1结合则取反; ......
设置:
1. Tools/Projects and Solutions/VC ++ Directories
Inlcude files: C:\Program Files\MATLAB\R2009a\extern\include
Library files: C:\Program Files\MATLAB\R2009a\extern\lib
2. Property
Configuration Properties/Linker
......
哈哈!有幸在某网站发现这篇文章,读罢,觉得蛮有道理,发来大家一起共勉之
总是被同学们问到,如何学习C和C++才不茫然,才不是乱学,想了一下,这里给出一个总的回复。
' J$ |0 ?! p% w" t5 D6 D: c9 |0 B
一家之言,欢迎拍砖哈。
1、可以考虑先学习C.
/ U$ X+ X/ P; Y ......
1.求下面函数的返回值( 微软)
int func(x)
{
int countx = 0;
while(x)
{
countx ++;
x = x&(x-1);
  ......