R.Wieser
2013-01-01 13:50:27 UTC
Hello All,
My first steps with VC8 express (Win XP), and I'm compiling a open-source
game called BZFlag.
Somewhere in there here is a
std::ofstream(filename.c_str(), mode);
command, and normally it works well. The the filename is comprized outof a
predefined path (into an existing folder), a name part provided by the user
and a fixed extension.
But users are downright silly beings, not knowing that, for example, a colon
":" is not a valid character in a (windows filesystem) filename. So they
sometimes use them.
The problem is that as a programmer I expected that the "std::ofstream"
function would barf on it so the user could be told to cleanup its filename.
Alas, nothing of the sort.
when I provide a filename like "C:\\foo:bar.tmp" a file named "foo" is
created, but its always zero bytes.
I've tried looking at several status flags (good(), bad() , is_open(), etc),
but none of them seem to, in the above case, indicate anything amiss.
[TL;DR - start reading here]
So, the question is : how does std::ofstream tell me (if at all) that the
above failed and/or how do I detect nothing got written to the file (did
look for but could not find a function (somehow) returning the ammount of
data written into the targetted file).
Regards,
R.Wieser
P.s.
Although I have programming experience, I'm a newbie in regard to "Visual
C++ 2008 Express edition" and the used language therein ...
My first steps with VC8 express (Win XP), and I'm compiling a open-source
game called BZFlag.
Somewhere in there here is a
std::ofstream(filename.c_str(), mode);
command, and normally it works well. The the filename is comprized outof a
predefined path (into an existing folder), a name part provided by the user
and a fixed extension.
But users are downright silly beings, not knowing that, for example, a colon
":" is not a valid character in a (windows filesystem) filename. So they
sometimes use them.
The problem is that as a programmer I expected that the "std::ofstream"
function would barf on it so the user could be told to cleanup its filename.
Alas, nothing of the sort.
when I provide a filename like "C:\\foo:bar.tmp" a file named "foo" is
created, but its always zero bytes.
I've tried looking at several status flags (good(), bad() , is_open(), etc),
but none of them seem to, in the above case, indicate anything amiss.
[TL;DR - start reading here]
So, the question is : how does std::ofstream tell me (if at all) that the
above failed and/or how do I detect nothing got written to the file (did
look for but could not find a function (somehow) returning the ammount of
data written into the targetted file).
Regards,
R.Wieser
P.s.
Although I have programming experience, I'm a newbie in regard to "Visual
C++ 2008 Express edition" and the used language therein ...