Skip to content

Instantly share code, notes, and snippets.

@Zrufy
Created February 11, 2022 08:44
Show Gist options
  • Save Zrufy/46aabef46cbd50191da5c9ef6e703317 to your computer and use it in GitHub Desktop.
Save Zrufy/46aabef46cbd50191da5c9ef6e703317 to your computer and use it in GitHub Desktop.
C++ method to get the current directory, i.e. .EXE path.
#include <Windows.h>
#include <string>
std::string GetCurrentDirectory()
{
char buffer[MAX_PATH];
GetModuleFileNameA(NULL, buffer, MAX_PATH);
std::string::size_type pos = std::string(buffer).find_last_of("\\/");
return std::string(buffer).substr(0, pos);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment