environment variables in c++
hello
how can i get environment variable value in c++ program? thanks in advance -- s3b0 |
I don't think there's a specific C++ interface but you can certainly use the C mechanism.
At the top of the file, add the line [code]#include <stdlib.h>[/code> Then, to get the environment variable: Code:
char * var = getenv("HOME"); Hope that helps, — Robert J. Lee |
yes
that's what i was looking for:) thanks -- s3b0 |
If u want all the environmental variables, u can try this program
#include<unistd.h> extern char **environ; int main() { int i; for(i=0;environ[i]!=NULL;i++) printf("%s\n",environ[i]); return 0; } here environ is a global predefined variable Dileep |
Or even (using C++ style I/O):
Code:
#include <iostream> |
That is true but for that we have to give parameters to main.
|
envp is (somewhat) depreciated. mabye not in the formal sense, but i wouldnt reccomend using it. environ is a cleaner solution.
|
All times are GMT -5. The time now is 08:54 PM. |