【发布时间】:2016-10-14 09:04:40
【问题描述】:
当我运行以下代码时:
char const * path = "/path/to/file";
std::fstream fs;
fs.open(path, fstream::in | fstream::out | fstream::binary);
if (!fsWave) {
LOGE("open, Error opening file %s", path);
}
它打印错误日志open, Error opening file /path/to/file
但是,以下工作顺利:
FILE * pf = NULL;
if(NULL == (pf = fopen(path, "w+b"))) {
LOGE("open, Error opening file %s", path);
}
顺利,我的意思是,它不打印错误日志并且确实在指定位置创建文件。
设置
- Android Studio 2.2.1
- NDK 12.1.2977051
- 清单中包含的权限
android.permission.WRITE_EXTERNAL_STORAGE、android.permission.READ_EXTERNAL_STORAGE - 测试设备 - 三星 S6
可能是什么原因,fstream::open() 失败了?
【问题讨论】:
-
一般in/out confusion?
fopen调用的语义与您的 fstream 版本不同。
标签: android c++ android-ndk fstream