• Advertisement
Sign in to follow this  

deprecated

This topic is 4235 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

Hello, Whenever I use strcpy, a warning is shown strcpy is deprecated. So, which function should I use then (as vor vsprintf)? -Stenny

Share this post


Link to post
Share on other sites
Advertisement
I'd just go with std::string. You can do 'easy' string formatting with that and when you need it to be an 'old-C' pointer to a character array you can use its c_str() method.

Share this post


Link to post
Share on other sites
VC++ 2k5 ships with safe versions of these C stdlib functions. Either use those or get rid of C runtime functions altogether if you use C++.

Share this post


Link to post
Share on other sites
The MSDN page for strcpy points here

However, if you're using C++ you really should be using std::string instead.

Share this post


Link to post
Share on other sites
Instead of strcpy_s, it may be even better to use StringCchCopy(), along with the rest of the string functions from strsafe.h.

Here's a page about all the string manipulation functions you can use from strsafe.h. It lists the functions you should not be using (like strcpy() and vsprintf()), and what you should be using instead of each one (like StringCchCopy() and StringCchVPrintf())
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/strings/usingstrsafefunctions.asp

I guess it's better to use the functions that have Cch (character count) in their name instead of their Cb (byte count) counter-parts, but I'm not 100% sure on that.

And yeah, the best option of all is to use std::string.

Share this post


Link to post
Share on other sites
Pretend that header file doesn't exist.

Either go with the normal C library functions (if you're using C) or use std::string (if you're using C++).

Share this post


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

  • Advertisement