#include #include using namespace std; extern char **environ; void PrintValue(string value); int main() { string name{"SILLY"}; cout << endl; string sillyVar{"SILLY=Now I am"}; cout << "\tusing string sillyvar " << endl; cout << endl; PrintValue("LOGNAME"); PrintValue(name); cout << "The environ pointer is " << environ << endl; if (putenv(const_cast(sillyVar.c_str())) == -1) { cerr << "Unable to change the SILLY environment variable" << endl; } else { PrintValue(name); } cout << "The environ pointer is " << environ << endl; cout << endl; cout << "Changing the value of sillyVar, DO NOT DO THIS" << endl; sillyVar = "SILLY=No WAY!!"; PrintValue(name); cout << "Removing " << name << endl; if(-1 == unsetenv(name.c_str())){ cerr << "Unable to remove " << name << endl; } PrintValue(name); return 0; } void PrintValue(string name) { char * tmp; cout << endl; cout << "Searching for " << name << endl; cout << "\t"; tmp = getenv(name.c_str()); if (tmp != nullptr) { cout << name << " is " << tmp << endl; } else { cout << name << " is not in the environment. "<< endl; } cout << endl; return; }