Which function should I prefer for new projects?
StringCchVPrintf from strsafe.h or sprintf_s
Which function should I prefer for new projects? StringCchVPrintf from strsafe.h or sprintf_s
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I suggest using snprintf if you code in C (because
snprintfis in the C99 standard).If you code in C++, consider using std::ostringstream, which is in C++ standard library.
Both
snprintfandostringstreamshould be available on many systems, including non Windows ones.I generally suggest coding for standards when possible. It will ease the port of your software to other systems. Try to avoid (or at least be careful when) using functions only available in WinApi (AFAIK, there is no standard specification defining it; it is simply a proprietary implementation, and most other systems don’t have it).
If your application has a graphical interface, you could consider using a cross-platform toolkit library like e.g. Qt: it gives you an abstraction (the Qt API) which should work on several operating systems.