且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我应该在我的 C++ 代码中使用 printf 吗?

更新时间:2022-06-17 05:49:29

我的学生,先学cincout,再学printf 后来,绝大多数人更喜欢 printf(或更常见的是 fprintf).我自己发现 printf 模型具有足够的可读性,因此我已将其移植到其他编程语言中.Olivier Danvy 也是如此,他甚至使它成为类型安全的.

My students, who learn cin and cout first, then learn printf later, overwhelmingly prefer printf (or more usually fprintf). I myself have found the printf model sufficiently readable that I have ported it to other programming languages. So has Olivier Danvy, who has even made it type-safe.

如果您有一个能够对 printf 调用进行类型检查的编译器,我认为没有理由不在 C++ 中使用 fprintf 和朋友.

Provided you have a compiler that is capable of type-checking calls to printf, I see no reason not to use fprintf and friends in C++.

免责声明:我是一个糟糕的 C++ 程序员.

Disclaimer: I am a terrible C++ programmer.