ÓÃ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
Ïà¹ØÎĵµ£º
Ö¸Õë,ÖÚËùÖÜÖª,ʱΪһÄÚ´æµØÖ·.Å׿ªOS¼¶±ð»ò¸üµÍµÄÓ²¼þ¼¶±ð²»Ëµ,½ö¶ÔÓ¦ÓÃÄÚµÄʹÓýøÐÐССµÄÒܲâÌÖÂÛ.
Ê×ÏÈ,ÔÚÓ¦ÓÃÄÚ,ÓÃmallocÉêÇëµ½µÄÒ»¿éµØÖ·Ó¦¸ÃÊÇÁ¬ÐøµÄ(²Â²â,Âß¼ÉÏÁ¬Ðø,ʵ¼ÊÉÏÎïÀíÈçºÎ·Ö²¼²»Óè¹Ø×¢).
Æä´Î,Êý¾Ý´æÔÚÔÚÄÚ´æÖж¼ÊÇÒÔ2½øÖÆÐÎʽ´æ·Å.²»´æÔÚÊý¾ÝÀàÐÍ,Òò´Ë,¶ÔÄÚ´æÊý¾ÝµÄ²Ù×÷,Ö»Òª×ñѽø³öÀàÐÍÒ»Ö¼´¿É.
´ ......
1.ÊDz»ÊÇÒ»¸ö¸¸ÀàдÁËÒ»¸övirtual º¯Êý£¬Èç¹û×ÓÀา¸ÇËüµÄº¯Êý²»¼Óvirtual ,Ò²ÄÜʵÏÖ¶à̬?
virtualÐÞÊηû»á±»ÒþÐμ̳еġ£private Ò²±»¼¯³É£¬Ö»ÊÂÅÉÉúÀàûÓзÃÎÊȨÏÞ¶øÒÑ¡£virtual¿É¼Ó¿É²»¼Ó¡£×ÓÀàµÄ¿Õ¼äÀïÓи¸ÀàµÄËùÓбäÁ¿(static³ýÍâ)¡£Í¬Ò»¸öº¯ÊýÖ»´æÔÚÒ»¸öʵÌå(inline³ýÍâ)¡£×ÓÀา¸ÇËüµÄº¯Êý²»¼Óvirtual ,Ò²ÄÜʵÏÖ¶àÌ ......
1.ÇóÏÂÃ溯ÊýµÄ·µ»ØÖµ£¨ ΢Èí£©
int func(x)
{
int countx = 0;
while(x)
{
countx ++;
x = x&(x-1);
  ......
Ò»¡¢³ÌÐòÕæÚÐ
1.³ÌÐò¾ÍÊÇ“°áÊý”
¶¯×÷£º¶ÁÈ¡——¼¼Êõ——д³ö£¨ÊäÈë——´¦Àí——Êä³ö£©
Êý¾Ý½á¹¹¾ö¶¨Êý¾ÝÈçºÎ×éÖ¯£¬°á¶¯ÆðÀ´Ð§Âʽϸß
Ëã·¨ÓïÑÔ¾ ......
Õâ¶ÎÔ´ÂëÄÜÔÚlinuxÏÂÔËÐУ¡£¡£¡ ÄÜʶ±ðСÊý
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
/*#define NULL 0*/
/* ×Ô¶¨Òå±äÁ¿ */
#define&n ......