K
Kristofer Pettijohn
I am trying to open a file in in+out+binary mode, and if the file
does not exist I want to create it.. this is the snippit of code
I am using:
fHistory.open(filename.c_str(),
std::ios::in | std::ios:
ut | std::ios::binary);
if (!fHistory.is_open()) {
fHistory.open(filename.c_str(),
std::ios::in | std::ios:
ut | std::ios::trunc | std::ios::binary);
}
if (!fHistory.is_open()) {
throw CException("Error creating " + filename);
}
fHistory.write("Test", 4);
If I delete the file specified in "filename", compile and run, it
creates a file of zero bytes; if I run again, it writes the block
"Test" to the file. I'm not sure what I'm doing wrong or overlooking,
but if someone could shed some light, I would greatly appreciate it!
Thanks!
does not exist I want to create it.. this is the snippit of code
I am using:
fHistory.open(filename.c_str(),
std::ios::in | std::ios:
if (!fHistory.is_open()) {
fHistory.open(filename.c_str(),
std::ios::in | std::ios:
}
if (!fHistory.is_open()) {
throw CException("Error creating " + filename);
}
fHistory.write("Test", 4);
If I delete the file specified in "filename", compile and run, it
creates a file of zero bytes; if I run again, it writes the block
"Test" to the file. I'm not sure what I'm doing wrong or overlooking,
but if someone could shed some light, I would greatly appreciate it!
Thanks!