C++, regarding fprintf and ofstream

社会主义新天地 提交于 2019-12-05 10:22:10

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/

You can't. You just write the string to the stream.

If you mean you want to provide some additional formatting to the string (like right justified with space padding), then you can use the I/O manipulators setfill(' ') (set the fill character to be the space character) and setw(length) (setting the width of the output). If you want something that mimics the syntax of the C style format strings, you can use Boost.format.

std::cout << boost::format("%s") % "SomeStringValue";
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!