gpt4 book ai didi

C++ MAC OS X 无法写入 ~/Library/Application Support/

转载 作者:行者123 更新时间:2023-11-30 01:28:49 32 4
gpt4 key购买 nike

如果我将文件保存在 .app 包中,它可以保存,但苹果建议将文件保存在应用程序支持中在

~/Library/Application Support/appname

~/Library/Application Support/bundleid

我都试过了,但我总是遇到异常。我正在获取应用程序支持的路径,即

/Users/myname/Library/Application Support/com.company.appname/

/Users/myname/Library/Application Support/AppName/

com.company.appname 在我的 info.plist 中正确指定,AppNameproduct AppName.app,所以路径看起来是正确的。

{
FilepathProcessor::pathForFile(fpath, "menustate", ".sav",
PATH_TO_DESTINATION_SAVE_LOAD_FOLDER);

std::ofstream file;
file.exceptions(std::ofstream::eofbit | std::ofstream::failbit |
std::ofstream::badbit);
INFO_ARG("prepare to save to '%s'", fpath.c_str());

try {
file.open(fpath.c_str(), std::ios::out | std::ios::binary |
std::ios::trunc);
ERROR_IF_ARG(!file.is_open(), "couldnt open file for saving at '%s'",
fpath.c_str(), return);

//will pass this point

//exception happens by first write
WRITE_INT_TO_BINFILE(file, episode);

//...

}
catch (std::ofstream::failure e) {
ERROR_IF_ARG(true, "exception %s", e.what(), return);
}
file.close();
}

输出:

INFO : prepare to save to '/Users/myname/Library/Application
Support/com.comapny.appname/menustate.sav' [CALLED BY : saveToFile]

ERROR!
Text : exception basic_ios::clear

最佳答案

该目录不会自动为您创建。在保存文件之前,首先需要检查目录是否存在,如果不存在,则需要创建目录。

关于C++ MAC OS X 无法写入 ~/Library/Application Support/<appname>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6993527/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com