0

Is it possible to set format of the output to file so I could write to file like printf writes to console?

printf("%s\\\n", "something");

std::ofstream myfile;
myfile.open ("somefile", ofstream::in | ofstream::out | ofstream::app); //debug
myfile << ""; // can I use somehow pattern like %s?
6

3 Answers 3

2
fprintf(FILE*, ....)

but it isn't wise to mix and match. Use new-style streams wherever possible.

http://www.cplusplus.com/reference/ios/ios_base/setf/

1

If you're looking for a printf-like solution in C++, I'd suggest Boost.Format library:

myfile << boost::format("%s\\\n") % "something";
0

Have you tried Boost.Format, it uses printf() compatible format strings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.