如何使用 GetPrivateProfileString() 从当前目录上升到目录

How to go up a directory from current directory with GetPrivateProfileString()

我正在尝试使用 GetPrivateProfileString 从 ini 文件中读取我的程序的授权详细信息。我想上去 directory/Folder/File.ini) 但不知道该怎么做

我试过了GetFullPathName()

void ini {


std::string iniPath = "/Ice/Ice.ini";
    LPWSTR inipath = A2W_EX(iniPath.c_str(), iniPath.length());



    DWORD IniPath = std::strtoul(iniPath.c_str(), NULL, 16);


    std::string playerUsername;

    std::string playerPassword;

    TCHAR iniauthChar[32];



    playerUsername = GetPrivateProfileString(authheader, authuser, 0, iniauthChar, 256, inipath);
    playerPassword = GetPrivateProfileString(authheader, authpass, 0, iniauthChar, 256, inipath);



}

这是我的 ini 文件,位于上面的目录

[AUTH]
Username=
Password=

对于 Windows 上的目录路径,您应该使用 \ 而不是 /

#include <windows.h>
#include <iostream>

int main()
{
    LPWSTR fn = L"Ice\Ice.ini";

    wchar_t buf[MAX_PATH];      
    GetFullPathNameW(fn, MAX_PATH, buf, NULL);

    std::wcout << buf << std::endl;
}

或使用 ANSI 字符串:

#include <windows.h>
#include <iostream>

int main()
{
    LPSTR fn = "Ice\Ice.ini";

    char buf[MAX_PATH];     
    GetFullPathNameA(fn, MAX_PATH, buf, NULL);

    std::cout << buf << std::endl;
}