C++,关于 fprintf 和 ofstream

标签 c++ ofstream printf

我已经使用 fprintf 一段时间了,我想问一个问题。此 fprintf 行的等价物是什么:

fprintf(OutputFile, "%s", "SomeStringValue");

使用ofstream ?

如何在 ofstream 中使用“%s”是我真正想知道的。如何获取下一个参数并将其打印为字符串?

最佳答案

你不使用它。

本质上等价于:

std::ofstream x("your_file");
x << "SomeStringValue";
x.close();

在几个引用页面中的任何一个上阅读它。如http://www.cplusplus.com/reference/ostream/ostream/operator%3C%3C/

关于C++,关于 fprintf 和 ofstream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18263461/

相关文章:

c# - 将基于 mfc 对话框的 Windows 应用程序转换为基于 Web

c++ - 用c++写一个循环文件

c - 需要帮助打印链接列表的内容

C printf() 不返回值

c - scanf %u 负数?

c++ - 无法在赋值中将 'int*' 转换为 'ABC*'

c++ - 将可见帧缓冲区读取到像素缓冲区对象

c++ - stringstream 和 nullptr 的子类

c++ - std::ofstream 打开文件并在特定偏移量中替换

c++ - 我想在 C++ 中使用 ifstream 和 ofstream 来模仿 C# 的 BinaryReader/BinaryWriter 功能