3

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

chema989
  • 3,962
  • 2
  • 20
  • 33
Avinash
  • 12,851
  • 32
  • 116
  • 186
  • it depends on what you find important, if it is performance, use snprintf, if it is type safety, use stringstream – AndersK Jul 20 '12 at 07:23

1 Answers1

6

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.

ForEveR
  • 55,233
  • 2
  • 119
  • 133