使用NDK, std::fstream open()失败,而fopen()正常工作,为什么?
With NDK, std::fstream open() is failing, whereas fopen() works correctly, Why?
当我运行以下代码时:
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
。如果该文件不存在,前者将创建一个新文件,后者将导致错误。
相关文章:
- 为什么在Windows上的VS 2019和Clang 9中"size_t"在没有标题的情况下工作
- 为什么我的 std::ref 无法按预期工作?
- 为什么std::condition_variable notify_all的工作速度比notify_one快(对于随机请
- 有人能解释一下为什么下界是这样工作的吗C++的
- 当我在第一个循环中使用"auto"时,它工作正常,但是使用"int"它会给出错误,为什么?
- 为什么stream::忽略未按预期工作
- 为什么常量词在重载运算符中不与 ostream 对象一起使用<<?
- 为什么 HeapFree() 不能正常工作?
- 为什么我们将单个或多维数组的大小声明为常量值?
- 为什么我在 AVR 中的中断无法正常工作?
- 为什么指针在对二维数组进行排序时无法正常工作?
- 为什么C++需要公共继承,忽略朋友声明,才能使动态向下工作?
- std::async 如何工作:为什么它会调用这么多次复制/移动?
- 静态 constexpr 函数在模板结构中工作,但不能在结构中工作.为什么?
- 禁用 GPU 使我的 CNTK 程序正常工作.为什么
- 为什么STD ::计数将常数传递给Lambda,而不是在弦上工作时而不是字符
- C++余弦在没有 std 命名空间的情况下工作 - 为什么
- c++的pow(2,1000)对于double来说通常太大了,但它正在工作.为什么
- 程序不是在win上工作,而是在mac上工作.为什么?
- 当我用字符串代替char时,代码可以完美地工作.为什么如此