问题描述
这件事让我疯狂。
为什么这样的简单输出文件流:
ofstream ofs;
ofs.open(" c:\ temp \ somefile.txt")
设置失败位?
在打开后立即调用ofs.fail()返回true。
This thing is driving me nuts.
why would a simple output file stream like this:
ofstream ofs;
ofs.open("c:\temp\somefile.txt")
set the fail bit?
calling ofs.fail() right after the open is returning true.
推荐答案
这只是一个例子。我知道字符串中的反斜杠需要转义
。该文件确实已创建。它只是因为我无法写入
,因为fail()返回true而我无法找出原因。
低级操作系统_open(或者其他)呼叫似乎每次成功创建
文件。在那之后的某个地方,我不知道为什么那一点是
设定。
That was just an example. I know a backslash inside a string needs to
be escaped. The file does get created. Its just that I can''t write
anythng into it because fail() returns true and I can''t figure out why.
The low level OS _open (or whatever) call seems to successfully create
the file everytime. Somewhere after that I don''t know why that bit is
getting set.
Will Windoze让你把标签放在文件名中?请记住
\在C ++中很特别。
Will Windoze let you put tabs in a file name? Remember
\ is special in C++.
这篇关于为什么流失败()位设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!