C++: Setenv(). Undefined identifier in Visual Studio

前端 未结 4 1471
春和景丽
春和景丽 2020-12-09 19:51

Look my code seems to be correct, according to all the documentation I can find online. My IDE is MS Visual Studio Xpress 4 Windows Desktop 2012, and it\'s compiler is throw

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-09 20:17

    You can either use _putenv() which takes a string parameter as the string classSize=7;

    ostringstream classSize;
    classSize << "classSize=" << howManyInClass;
    _putenv(classSize.str().c_str());
    

    ...or (preferably) the security enhanced _putenv_s() that takes the key and the value as separate (const char*) parameters;

    ostringstream classSize;
    classSize << howManyInClass;
    _putenv_s("classSize", classSize.str().c_str());
    

提交回复
热议问题