I have function saveData() which writes to a text file. I would like to tell it whether to append ios::app or create new ios:ut ... How do i pass these flags as a parameter to saveData(...)?
I have function saveData() which writes to a text file. I would like to tell it whether to append ios::app or create new ios:ut ... How do i pass these flags as a parameter to saveData(...)?
One option is to have a std::ostream as the parameter. If you really want to open the file according to a filename and format flags then std::ios::fmtflags should be the type of the format flags parameter.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
It is probably correct but if you really need the filename variable, it would be better to write it as:Originally Posted by csonx_p
Actually, if you need filename, why not make it a std::string?Code:char filename[MAX_PATH] = "contract.txt"; ofstream outfile(filename, flag);
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Use the c_str() member function, e.g.,
EDIT:Code:std::string filename = "contract.txt"; ofstream outfile(filename.c_str(), flag);
By the way, it looks like I got it wrong: the std::ios::fmtflags is for format flags (duh). On the other hand, the source you quoted gives std::ios_base:penmode, so perhaps you can try std::ios::openmode as the type.
Last edited by laserlight; 01-05-2009 at 12:55 PM.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)