C++, regarding fprintf and ofstream
C++, regarding fprintf and ofstream
我已经使用fprintf
一段时间了,我想问一个问题。这条fprintf
线的等价物是什么:
fprintf(OutputFile, "%s", "SomeStringValue");
使用CCD_ 3?
如何在ofstream
中使用"%s"是我真正想知道的。如何获取下一个参数并将其打印为字符串?
你不用它。
等价物本质上是:
std::ofstream x("your_file");
x << "SomeStringValue";
x.close();
去几个参考页中的任何一页上读一下。例如http://www.cplusplus.com/reference/ostream/ostream/operator%3C%3C/
你不能。你只需将字符串写入流中。
如果您的意思是要为字符串提供一些额外的格式设置(如用空格填充右对齐),那么您可以使用I/O操纵器setfill(' ')
(将填充字符设置为空格字符)和setw(length)
(设置输出宽度)。如果你想要一些模仿C风格格式字符串语法的东西,你可以使用Boost.format.
std::cout << boost::format("%s") % "SomeStringValue";
相关文章:
- C++核心准则 C35 对于接口类"A base class destructor should be either public and virtual, or protected and nonv
- 为什么C++逐位AND运算符在不同大小的操作数中表现为这样
- 为什么 Clang 不允许"and"作为函数名称?
- 位阵列上的快速AND运算
- 是否可以在 C++03 中定义'move-and-swap idiom'等效项
- BoostPython and CMake
- std::ofstream 作为类成员删除复制构造函数?
- OpenSSL BIO and SSL_read
- Gurobi GRBModel and GRBmodel in C++
- ofstream::close() 是否在 Linux 上调用同步?
- std::visit and std::variant usage
- SHBrowseForFolder with BIF_BROWSEFORCOMPUTER and SHGetPathFr
- 如何在软件代码中使用ofstream创建文件
- Directx12 and keystrokes
- Using ifstream, ofstream and fstream
- Openmp with ofstream and system command
- C++, regarding fprintf and ofstream
- Ifstream and Ofstream problems
- overriding istream and ofstream
- fstream and ofstream