在android c ++ source中输出到文件

时间:2012-12-13 23:06:37

标签: android android-ndk android-source android-build

我已经设法从源代码编译android并安装在我的手机上。我应该从一开始就说我不是c ++开发人员,但我曾希望能够解决如何将变量中保存的数据输出到文件中。

经过一段谷歌搜索后,我想出了以下代码:

#include <iostream>
#include <fstream>
using namespace std;

ofstream myfile;
myfile.open ("/data/wav.raw");
myfile < mMixBuffer;
myfile.close();

frameworks/base/services/audioflinger/AudioFlinger.cpp: In member function 'virtual bool android::AudioFlinger::MixerThread::threadLoop()':
frameworks/base/services/audioflinger/AudioFlinger.cpp:1769: error: 'ofstream' was not declared in this scope
frameworks/base/services/audioflinger/AudioFlinger.cpp:1769: error: expected ';' before 'myfile'
frameworks/base/services/audioflinger/AudioFlinger.cpp:1770: error: 'myfile' was not declared in this scope

在此之后无法正常工作我尝试再次出现编译错误:

int fd;
fd = ::open("/data/wav.raw",O_WRONLY | O_APPEND);
::write(fd,mMixBuffer,minBufferSize);
::close(fd);

frameworks/base/services/audioflinger/AudioFlinger.cpp: In member function 'virtual bool android::AudioFlinger::MixerThread::threadLoop()':
frameworks/base/services/audioflinger/AudioFlinger.cpp:1770: error: '::open' has not been declared
frameworks/base/services/audioflinger/AudioFlinger.cpp:1770: error: 'O_WRONLY' was not declared in this scope
frameworks/base/services/audioflinger/AudioFlinger.cpp:1770: error: 'O_APPEND' was not declared in this scope

如果从上面不清楚,我试图将大小为mMixBuffer的变量minBufferSize的内容附加到文件/data/wav.raw。有谁知道我怎么能做到这一点?

1 个答案:

答案 0 :(得分:1)

/ data /目录无法修改。您将无法获得相同的权限。尝试/ mnt / sdcard(或)/ data / data /.