이 함수는 C 스타일 문자열을 사용하는 것 같습니다. 그러나 C++ String으로 변환 할 수 있습니다. 당신은 쉽게 찾을 경우
#define MAX_LENGTH 256 // a custom maximum length, 255 characters seems enough
#include <cstdlib> // for malloc and free (optional)
#include <string>
using namespace std;
// other code
char *buffer = malloc(MAX_LENGTH);
string temp_dir;
if (GetTempPath(MAX_LENGTH, buffer) != 0) temp_dir = string(buffer);
else {/* GetTempPath returns 0 on error */}
free(buffer); // always free memory used for the C-Style String
// other code
또한 new[]
및 delete[]
를 사용하여 메모리를 할당하고 해제 할 수 있습니다! 정적 메모리 할당도 사용할 수 있습니다!
도움이 되었기를 바랍니다. : D