Gary Wessle wrote:
Hi
I have a class with a private attribute std::fstream* fs_status;
in the ctor, I have
fs_status.open( f_name.c_str(), std::string::ios out | std::string::ios::app |
std::string::ios::out );
I basically need to create it if it is not there and
to open it for append AND for reading if it is there.
I am doing it right?
No.
First, fs_status should not be a pointer.
Second, if fs_status is a pointer, then your syntax is correct.
Third, what are all those std::string::'s doing in there?
Fourth, initalize fs_status in your class's initialization list, i.e.
my_class::my_class( const std::string& f_name )
: fs_status( f_name.c_str(), std::ios::out | std::ios::in |
std::ios::app )
{
// constructor body.
}
Note: I may have an incorrect set of flags (Josuttis table 13.33
indicates I might).
It looks like that in/out/append is not possible as a generic parameter,
it can either be in/out/trunc or out/app if it doesn't exist, but
in/out/app doesn't seem to be valid.
DISCLAIMER: I haven't played with iostream modes in a long time.
Someone with better knowledge than me should correct it.