当我运行以下代码时:
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()
失败的原因是什么?
C文件API模式"w+"
对应于iostream打开模式in | out | trunc
,而不是in | out
。如果该文件不存在,前者将创建一个新文件,后者将导致错误。