C++, regarding fprintf and ofstream

aresz picture aresz · Aug 16, 2013 · Viewed 14.2k times · Source

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?

Answer

UpAndAdam picture UpAndAdam · Aug 16, 2013

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/