简体   繁体   English

简单的C ++写文件在Mac OS X App中不起作用-为什么? (为什么是我?)

[英]Simple C++ write-to-file not working within Mac OS X App - why? (and why me?)

The code is simple enough: 代码很简单:

#include <iostream>
#include <fstream>
#include <string>

int main(int argc, char* argv[] )
{
    std::ofstream theStream;
    theStream.open("trash.txt");
    theStream << "some words" << std::endl;
    theStream.close();
}

If I run it from the command line then I get the expected file in the same directory. 如果我从命令行运行它,那么我会在同一目录中获得所需的文件。 If a package the contents of the executable within a MacOS .app, then no file is written anywhere. 如果将MacOS .app中可执行文件的内容打包,则不会在任何位置写入文件。 (Or perhaps it is just promptly erased?) (或者只是立即删除?)

Here's the simple script I'm using to place the executable into the .app. 这是我用来将可执行文件放入.app的简单脚本。 Perhaps that is where I'm going wrong. 也许那就是我要去的地方。

#!/bin/bash

appName=MyApp
if [ $1 ] 
then 
    appName=$1
else 
    echo "usage: convertToApp executableFile"
    exit
fi

if [ -e "$appName" ] 
then
    mkdir $appName.app
    mkdir $appName.app/Contents
    mkdir $appName.app/Contents/MacOS
    mkdir $appName.app/Contents/Resources
    cp $appName $appName.app/Contents/MacOS/$appName
    echo -n 'APPL????' > $appName.app/Contents/PkgInfo
else
    echo "specified file does not exist"
fi

Any idea why I can't see the file I want to see? 知道为什么我看不到我想看的文件吗?

尝试使用完整路径或更改当前工作目录,而不是“ trash.txt”。

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

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