sprinf() vs sprint_s()

I have some code that I wanted to upgrade for a MS 2003 to MS 2005 Visual Studio
The code is quite complex but it will compile in 2005 but I have several warnings.
how do I learn the differences between using these functions, so I can substitute the new one from the deprecated version?
code copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const char*  Cm110s::display_mode_string( Mode mode )

{

	static char msg[25];

	

	switch( mode )

	{

		case M75NS:

			sprintf(msg,"75 BPS SHORT");

			break;    

end copy
Randy
I don't think sprinf is really deprecated according to the C++ standard, but I'm not sure. sprint_s is a function that microsoft want you to use instead but it's non-portable and will not work on other compilers.

In C++ why not use std::ostringstream and std::string instead?
http://www.informit.com/blogs/blog.aspx?uk=Theyre-at-it-again

Take Peter87's suggestion. Otherwise simply use snprintf() instead of sprintf().

http://en.cppreference.com/w/cpp/io/c/fprintf

Edit: d'oh, I'm pretty sure Microsoft didn't implement it so never mind.
Last edited on
I'll look at std::ostringstream and std::string and see how much changing that would involve, this function is used over 40 times in the project in more than 1 *.cpp file.

thank you,
Randy
Topic archived. No new replies allowed.