0

why is this feature not visible in a simple console application c++ vs2017.

#include <iostream>
#include <string>
#include <cstdlib> // setenv here or <stdlib.h>

int main()
{
    setenv("PYTHONPATH", ".", 1);
    //...
}

setenv error C3861: identifier not found

jenokizm
  • 9
  • 5
  • As far as I can find using online references, `setenv` is defined in `stdlib.h` but not in `cstdlib`... just include the C header instead, using `extern "C"` ? – Magix May 07 '18 at 11:07
  • There is no such function in the C++ standard, only `getenv`. – Some programmer dude May 07 '18 at 11:07
  • ok. unfortunately stdlib.h and extern "C" wrapper did not help( – jenokizm May 07 '18 at 11:22
  • I temporarily use this solution: int setenv_my(const char *name, const char *value, int rewrite) { std::stringstream sstr; sstr << name << '=' << value; return _putenv(sstr.str().c_str()); } – jenokizm May 07 '18 at 11:22
  • You shouldn't. You should use a standard header from somewher. Don't write software using 1000 crutches. – user207421 May 07 '18 at 11:31

0 Answers0