Hello. Tell me what fprintf will look like.

 int fprintf( FILE *stream, const char *format, ... ); 

if I use ofstream &fp instead of FILE*fp ?

 ofstream fp("oops.txt"); 

Here, fp not a pointer, as usual. How then?

ps or what function is better to use to record data into a file, if using ofstream ?

  • It is better not to interfere with everything in a heap. Use C. - avp

2 answers 2

The fprintf function is not needed. In C ++, for recording in streams (not only ofstream, but of all classes inherited from ostream), the operator <<

 fp << "Hello, world!" << endl; fp << "2 + 2 = " << (2 + 2) << endl; 

Details about the input-output files can be read for example by reference.

  • aa, ok thank! - Kollibry

If you use ofstream, then fprintf will not look any way. They are from different libraries.