所以我尝试下一个代码:
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <boost/filesystem/v3/path.hpp>
#include <boost/filesystem/v3/operations.hpp>
#ifdef WIN
#include <Windows.h>
#endif
void setEnviromentVariable(std::string name, boost::filesystem::path value)
{
if ( getenv (name.c_str())==NULL)
{
std::cout << "Hit ENTER to restart application in order to agree with the next terms of use: do not eat my bytes!)" << std::endl;
std::stringstream VAR;
VAR << name<< "=" << value.native().c_str();
#ifdef WIN
std::stringstream VAL;
VAL << value.native().c_str();
if( !SetEnvironmentVariable(TEXT(name.c_str()), TEXT(VAL.str().c_str())))
{
printf("SetEnvironmentVariable failed (%d)\n", GetLastError());
}
#else
setenv(VAR.str().c_str());
#endif
std::cin.get();
}
}
int main(int argc, char *argv[])
{
boost::filesystem::path full_path( boost::filesystem::current_path() / "assets/" );
setEnviromentVariable("TCL_LIBRARY", full_path);
}
我的代码有什么问题?为什么它没有设置任何环境变量,为什么它没有显示任何错误?(WIN代码就是以此为基础的。)