[HH] c++ strings?

Jerry Feldman gaf at blu.org
Tue Nov 20 09:21:52 EST 2012


On 11/20/2012 06:12 AM, Mark Woodward wrote:
> On 11/20/2012 01:55 AM, David Kramer wrote:
>>
>> You probably want sprintf, which is like printf except it outputs a
>> string instead of writing the output to stdout.
>>
>> http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/
>
> You never, ever, really never, want to use sprintf in any program.
> Each and every occurrence of "sprintf" should be replaced by snprintf
> as soon as possible. The sprintf call is unbounded is a stability risk
> as well as a potential security hole.
C++ native strings are identical to C language strings using all the C
library functions, but there is a very rich C++ string class that is
part of the STL (standard template Library)(std::string).
http://www.cplusplus.com/reference/string/string/

IMHO, as a long time contractor I always recommend coding in the same
style that is prevalent in the companies that I have worked in. When
coding in C++ I rarely use the C language strings or printfs. Again,
from a purist standpoint, in C++ you should generally use the cout set
of input/output operators.

-- 
Jerry Feldman <gaf at blu.org>
Boston Linux and Unix
PGP key id:3BC1EB90 
PGP Key fingerprint: 49E2 C52A FC5A A31F 8D66  C0AF 7CEA 30FC 3BC1 EB90


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 543 bytes
Desc: OpenPGP digital signature
URL: <http://lists.blu.org/pipermail/hardwarehacking/attachments/20121120/cb67fa3b/attachment.sig>


More information about the Hardwarehacking mailing list