- Make a const char * and do a constant cast.
const char* sillyVar{"SILLY=Now I Am"};
...
if (putenv(const_cast<char *>(sillyVar)) == -1) {
- Declare a c++ style string, use c_str(), and do a constant cast
string sillyVar{"SILLY=Now I am"};
...
if (putenv(const_cast<char *>(sillyVar.c_str())) == -1) {
- Declare an array of characters.
char sillyVar[] = "SILLY=Now I Am";
...
if (putenv(sillyVar) == -1) {
- Copy a string, but you need to free it later.
char* sillyVar = strdup("SILLY=Now I Am");
...
if (putenv(sillyVar) == -1) {
...
free(sillyVar);