snprintf vs std::stringstream

泄露秘密 提交于 2019-12-11 03:48:04

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/11574391/snprintf-vs-stdstringstream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!