test4.cpp: In function 'int main()':
test4.cpp:7:29: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
putenv(win_center.c_str());
^
In file included from /usr/include/c++/4.8.2/cstdlib:72:0,
from /usr/include/c++/4.8.2/ext/string_conversions.h:41,
from /usr/include/c++/4.8.2/bits/basic_string.h:2815,
from /usr/include/c++/4.8.2/string:52,
from /usr/include/c++/4.8.2/bits/locale_classes.h:40,
from /usr/include/c++/4.8.2/bits/ios_base.h:41,
from /usr/include/c++/4.8.2/ios:42,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from test4.cpp:2:
/usr/include/stdlib.h:578:12: error: initializing argument 1 of 'int putenv(char*)' [-fpermissive]
externint putenv (char *__string) __THROW __nonnull ((1));
std::string:c_str() return a constant c-string (const char*). You cannot pass a constant to a function that accepts a non-constant reference or pointer (know that it doesn't appear to be that simple, looking into it right now):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <string>
void foo(int &a_ref) //we can modify the argument passed to foo
{ //which means that the caller's version of a can be modified
}
void bar(char *c_ptr)
{
}
int main()
{
constint a = -1;
//foo(a); // foo has access to and is able to change a, which is constant
foo(const_cast<int &>(a)); // okay, it isn't as simple as I suggested earlier
std::string s = "ER MER GERD";
bar(s.c_str()); // error, passing const char * to a non-constant pointer
bar(const_cast<char *>(s.c_str())); // okay I guess
}
So, in your case, putenv accepts a non-constant c-string, but you try to pass a constant to it which is invalid.
That is the only place i found that said it was depreciated. _putenv is not available in linux. Im not sure how much i would trust something said that only comes from microsoft anyways.
I was looking for a well portable solution