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?
deepspace
  • 771
  • 3
  • 11
  • 25

3 Answers3

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/

Mayur Patel
  • 945
  • 1
  • 7
  • 15
1

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

myfile << boost::format("%s\\\n") % "something";
awesoon
  • 32,469
  • 11
  • 74
  • 99
0

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

Johny
  • 1,947
  • 13
  • 23