简体   繁体   English

cstdio fopen和fclose在osx上无法正常工作

[英]cstdio fopen and fclose not working correctly on osx

I'm using tinyxml through openframeworks which uses cstdio for file access. 我正在通过使用cstdio进行文件访问的openframeworks使用tinyxml。 I can see the example program quite happily create and write files but there is no delete so my plan is to implement remove, but after trying to run this code in my own project it doesn't seem to create a file or notify me of an error. 我可以看到示例程序很高兴地创建和写入文件,但是没有删除,因此我的计划是实现删除,但是在尝试在自己的项目中运行此代码后,它似乎没有创建文件或通知我错误。

This code runs as expected on windows, just not on mac osx 10.8.5, no file is generated. 此代码可以在Windows上按预期运行,但不能在Mac osx 10.8.5上运行,不会生成文件。

#include <cstdio>

int main(int argc, const char * argv[])
{
    bool bClosed = false;
    bool bWritten = false;
    FILE* testFile;
    testFile = fopen(".\\test.xml", "w");
    if(testFile)
    {
       bWritten = fputs("test writing.", testFile);
       bClosed = !fclose(testFile);
    }
    return 0;
}

edit: i now know the file exists as can read from it, i just cant view it in finder, i have hidden files shown, its not found its way into the app's package contents. 编辑:我现在知道该文件存在,可以从中读取,我只是无法在finder中查看它,我显示了隐藏的文件,但未找到进入应用程序包内容的方式。

On a unix-like system (eg Mac OS X and Linux) a Windows path as 在类似Unix的系统(例如Mac OS X和Linux)上,Windows路径为

".\\test.xml"

should rather be 应该是

"./test.xml"

Anyway the simplest solution for this case might just be 无论如何,最简单的解决方案可能就是

"test.xml"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM