In my code, I use the following:
putenv("TZ=UTC");
tzset();
to set the time zone.
Declaration putenv()( this answer recommended setting an environment variable):
int putenv(char *string);
In the assembly, I use the set compiler flags -Wall -Wextra -Werror -std=c++0x, and because of this, I get an error:
timeGateway.cpp:80:18: error: ISO C++ forbids converting a string constant to 'char*' [-Werror=write-strings]
putenv("TZ=UTC");
^
I know that this error can be suppressed using:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
putenv("TZ=UTC");
#pragma GCC diagnostic pop
But it is very ugly.
My question is: what is the correct way to set an environment variable in C ++?
source
share