I'm making a simple game in DirectX and C++. But I want to create a directory in Documents for the settings etc.
But I don't know how I need to do this?
Can someone help me?
I'm making a simple game in DirectX and C++. But I want to create a directory in Documents for the settings etc.
But I don't know how I need to do this?
Can someone help me?
The C++11 standard n3337 does not know about directories. C++17 has <filesystem>
standard header.
If your implementation is C++17 compliant (it probably is not), use std::filesystem::create_directory
Otherwise, use operating system primitives. Be aware that the notion of directory can be OS specific (i.e. different in one OS from another, perhaps even between different file systems). For Windows, study the WinAPI (so consider CreateDirectoryA). For Linux, look into its syscalls(2) (so consider mkdir(2))
Some frameworks, notably Qt, POCO, Boost, provide common wrappers above them.
You can use a simple mkdir from <direct.h>
to create directory
_mkdir("C:\\Data\\FolderName");
You can use Visual Studio's <filesystem>
There is a function create_directory
that has the signature
template<class Path>
inline bool create_directory(
const Path& Pval
);
You can find the user's Documents directory using SHGetKnownFolderPath
which has the signature
HRESULT SHGetKnownFolderPath(
_In_ REFKNOWNFOLDERID rfid,
_In_ DWORD dwFlags,
_In_opt_ HANDLE hToken,
_Out_ PWSTR *ppszPath
);
In this case the REFKNOWNFOLDERID
you want to use is FOLDERID_Documents
Note this is specific to Visual Studio. The C++ <filesystem>
library is still in the works (i.e. experimental) for now, but hopefully is coming soon!
If you don't have C++17 yet and look for a platform agnostic solution, use ghc::filesystem. The header-ony code is compatible to C++17 (in fact a backport) and easy to migrate later on.