Sorry to keep hammering on this, but I\'m trying to learn :). Is this any good? And yes, I care about memory leaks. I can\'t find a decent way of preallocating the char*, be
You're supposed to use the ISO C++ conformant version _getcwd I think. There's no point returning a const string, and you should use free to deallocate (at least according to MSDN):
string getcwd()
{
char* a_cwd = _getcwd(NULL, 0);
string s_cwd(a_cwd);
free(a_cwd);
return s_cwd;
}
Of course you should also check if _getcwd() returns NULL.