• Advertisement
Sign in to follow this  

Quick question about strsafe.h functions

This topic is 4249 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm not quite sure I understand MSDN about using the strsafe.h functions. Let's use StringCbPrintf as an example. I'm particularly worried about the CbDest parameter, which is the size of the destination buffer (in bytes). If I have a character array 256 bytes long, do I use 256 or 255?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
From the linked page
cbDest
[in] Size of the destination buffer, in bytes. This value must be sufficiently large to accommodate the final formatted string plus the terminating null character.


So in your case, you should use 256.

Share this post


Link to post
Share on other sites
Why bother with all of those? They're a nasty hack to try to post-fix bad string habits rooted in language practices that are crufty and old...

I'd recommend strstream and the like, covered with convenience functions if need be.

Share this post


Link to post
Share on other sites
Quote:
Original post by JasonBlochowiak
Why bother with all of those? They're a nasty hack to try to post-fix bad string habits rooted in language practices that are crufty and old...

I'd recommend strstream and the like, covered with convenience functions if need be.

QFT

Although I'm sure you meant std::stringstream/boost::format.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement