In this post, we will see how to escape percent sign in printf Method in C++.
Escape percent sign in Printf Method in C++
printf()
method uses percent sign(%
) as prefix of format specifier.
For example:
To use number in prinf()
method, we use %d, but what if you actually want to use percent sign in the String.
Output
As you can see, it didn’t print output as expected.
If you want to escape percent sign in printf()
method, you can use % twice (%%
).
Here is an example:
Output
Further reading:
If you don’t require any formats in String, you can use puts
or fputs
as well.
Output
That’s all about how to escape percent sign in printf Method in C++.
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.