By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

Is use of the std::snprintf(. . .) std:: string method preferred over the plain snpri

P: 1
Is use of the std::snprintf(. . .) std::string method preferred over the plain C++ snprintf(. . .) function? If so what are the risks?
Nov 20 '15 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
snprintf is a C function. It is included in <stdio.h>.

If you are using your C++ compiler you would include <cstdio> which just includes <stdio.h>.

The only way I can answer this question is to say the printf family of functions can only work with built-in types. None of your user defined types can use these functions. So by using printf functions you built limits to your code and make it non-reusable and non-extensible.

Let me also add that if there are snprintf function calls buried throughout the code, each of these carries a part if the UI. There is no one place where the UI is controlled. By changing, or removing, one of these calls you have a cascading effect and can't see the complete effect of the change at the program level. In past decades this was called "spaghetti code".

Maye you could say more about your concerns.
Nov 20 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.