Is it bad practice to use C features in C++?

前端 未结 10 1938
悲哀的现实
悲哀的现实 2021-02-19 00:16

For example printf instead of cout, scanf instead of cin, using #define macros, etc?

10条回答
  •  情深已故
    2021-02-19 00:54

    You should definitely use printf in place of cout. The latter does let you make most or all of the formatting controls printf allows, but it does so in a stateful way. I.e. the current formatting mode is stored as part of the (global) object. This means bad code can leave cout in a state where subsequent output gets misformatted unless you reset all the formatting every time you use it. It also wreaks havoc with threaded usage.

提交回复
热议问题