用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
相关文档:
在上一篇中我们已经使用c语言实现了一个最简单的扩展模块,这一篇中将在其基础上进行功能的丰富。首先来考虑如何从外部的Python向C模块传递进参数,foo_bar2展示了如何向C模块传递整数,浮点数,字符串三个参数,其中"ids"指明了传入参数的数据类型。PyArg_ParseTuple负责对args进行解析,若解析失败则返回0.代码#include&n ......
哈哈!有幸在某网站发现这篇文章,读罢,觉得蛮有道理,发来大家一起共勉之
总是被同学们问到,如何学习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);
  ......
用过vista的朋友都知道 vista不知由于什么原因很多编译软件都不能正常工作了 vs6.0全部都说有已知的兼容性问题存在
当然你可以装好几个g的vs2005
寡人一直都想自学一门计算机语言
但是苦于找不到编译器
连最简单的hellowold都不能正常编译
汗
不多说
看我弄得
总算能用了
1.下载MinGW
http://sourceforge.net/pro ......
这段源码能在linux下运行!!! 能识别小数
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
/*#define NULL 0*/
/* 自定义变量 */
#define&n ......