I've been using fprintf
for a while now and I'd like to ask a question. What is the equivalent of this fprintf
line:
fprintf(OutputFile, "%s", "SomeStringValue");
using ofstream
?
How to use the "%s" in ofstream
is what I'd really like to know. How to take the next argument and print it as a string?
fprintf() in C fprintf is used to print content in file instead of stdout console. int fprintf(FILE *fptr, const char *str, ...);
The fprintf function is used for printing information to the screen. The fprintf function prints an array of characters to the screen: fprintf('Happy Birthday\n'); We often use the fprintf statement to show the user information stored in our variables.
ofstream is an output file stream. It is a special kind of ostream that writes data out to a data file.
ifstream is input file stream which allows you to read the contents of a file. ofstream is output file stream which allows you to write contents to a file. fstream allows both reading from and writing to files by default.
You don't use it.
The equivalent is essentially:
std::ofstream x("your_file");
x << "SomeStringValue";
x.close();
Go read about it on any of several reference pages. Such as http://www.cplusplus.com/reference/ostream/ostream/operator%3C%3C/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With