We Recommend

C++ The Core Language C++ The Core Language
C++: The Core Language is for C programmers transitioning to C++. It's designed to get readers up to speed quickly by covering an essential subset of the language. The subset consists of features without which it's just not C++, and a handful of others that make it a reasonably useful language.


Posted By

yuconner on 09/16/06


Tagged

environment


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

copyleft


get and put environment variables in C++


Published in: C++ 


  1. // char * getenv(const char * name);
  2. // int putenv(const char * var);
  3.  
  4. // getenv example
  5. std::string HOME_PATH = getenv("HOME");
  6.  
  7. // putenv example
  8. int stat = putenv("TEMP="/tmp");
  9. if( !stat ) {
  10. cout<<"failed to define environment variable"<<endl;
  11. }

Report this snippet 

You need to login to post a comment.