Namespaces
Variants
Views
Actions

std::getenv

From cppreference.com
< cpp‎ | utility‎ | program
Revision as of 11:34, 2 November 2012 by P12bot (Talk | contribs)

Defined in header <cstdlib>
const char *getenv( const char *env_var );

Searches for an environmental variable with name env_var in the host-specified environment list and returns information associated with it. The set of environmental variables and methods of altering it are implementation-defined.

Contents

Parameters

env_var - null-terminated character string identifying the name of the environmental variable to look for

Return value

Character string identifying the value of the environmental variable or NULL if such variable is not found.

Example

#include <iostream>
#include <cstdlib>
 
int main(int argc, char *argv[])
{
    std::cout << "Your PATH is: " << std::getenv("PATH") << std::endl;
}

Possible output:

Your PATH is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

See also

C documentation for getenv