Home
menubar
rss_feed

Previous Reference C++ Reference <cstdlib> Next Reference




C++ Reference: getenv()





getenv()


Declaration

char* getenv(const char* kcpEnvVarName);

Description

Retrieve the value of an environment variable. The parameter pointed to by the null-terminated string "kcpEnvVarName" is the name of the environment variable. The return value is its environment variable's value as a null-terminated string or NULL if the variable is undefined.

Example

#include <iostream>
#include <cstdlib>

int main() {
    using namespace std;

    char caEnvVarName[] = "SomeVariableName";
    char* cpEnvVarValue = getenv(caEnvVarName);

    if (cpEnvVarValue == 0) {
        cout << "Environment variable \"" << caEnvVarName
             << "\" does not exist." << endl;
    } else {
        cout << "Environment variable \"" << caEnvVarName
             << "\" = " << cpEnvVarValue << endl;
    }

    return 0;
}


Output:








Previous Reference C++ Reference <cstdlib> Next Reference




Home | Reference | Play Games! | Blog | Forum | Site Map | Contact Us


shadow bottom image