Freigeben über


sprintf/wsprintf Replacement

 

Are you thinking about using wsprintf method to create a string buffer? Think twice before doing anything wrong! MSDN documentation explicitly warns programmers to not use this API.

So, what alternative we can use instead?

sstream header gives us wstringstream class to create our own string streams. It’s easy, convenient and object oriented. Let’s try a simple example:

image

Above example demonstrates how you can concatenate a string buffer and an integer to form a single string.

In short, do not use banned APIs such as wsprintf. There are multiple ways of doing something and choose the safest and cleanest one!