As a C++ programmer I sometimes need deal with memory buffers using techniques from C. For example:
char buffer[512];
sprintf(buffer, \"Hello %s!\", userName.c_s
If a function gives you a method of knowing how many characters it will return, use it. Your sample GetCurrentDirectory is a good example:
DWORD length = ::GetCurrentDirectory(0, NULL);
Then you can use a dynamically allocated array (either string or vector) to get the result:
std::vector buffer(length, 0);
// assert(buffer.capacity() >= length); // should always be true
GetCurrentDirectory(length, &buffer[0]);