The getenv() Function

The ANSI function getenv() returns the value of an environment variable. getenv() takes a C-string containing an environment variable and returns its value. In the following example, getenv() detects the value of the environment variable PATH:

   #include   int main()  {    char * curr_path = getenv("PATH");    cout<

A typical output string of this program may look like this:


Using getenev() instead of a platform specific API has two advantages: your code is portable because getenv() is a standard functions, and the application doesn't need to link to MFC or Win API runtime libraries and dll's that have adverse effects on a program's speed and size.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles:


DevX is the leading provider of technical information, tools, and services for professionals developing corporate applications. 


Get exclusive access to the best technical information, tools, and services sent straight to your inbox.  

©2023 Copyright DevX - All Rights Reserved. Registration or use of this site constitutes acceptance of our Terms of Service and Privacy Policy.