snprintf 与 std::stringstream [英] snprintf vs std::stringstream

查看:63
本文介绍了snprintf 与 std::stringstream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力消除我的产品中的 SECURITY CODING 违规行为.我的代码有很多sprintf,coverity 工具建议我使用snprintf,但C++ 也有std::stringstream.使用 std::stringstream 代替 snprintf

I am working on removing SECURITY CODING violation in my product. My code has lot of sprintf, coverity tool is suggesting me to use snprintf, But C++ also has std::stringstream. Will it be a good idea to use std::stringstream in place of snprintf

推荐答案

std::stringstream 是类型安全的,使用运算符 <<,使用内部缓冲区,C++ 的一部分,没有那么快sprintf.
sprintf 不是类型安全的,不使用 C++ 操作符,使用外部缓冲区,使用 elipsis,它只能用于 POD 类型,继承自 C,速度快.

std::stringstream is typesafe, use operator <<, use internal buffer, part of C++, not so fast as sprintf.
sprintf is not typesafe, not use c++ operators, use external buffer, use elipsis, which can works only with POD types, inherited from C, fast.

这篇关于snprintf 与 std::stringstream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆