windows 如何转义 sprintf() % 标记,以便它们不会被识别为变量?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3206496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:47:31  来源:igfitidea点击:

How to escape sprintf() % marks so they wont be recognized as variables?

c++windows

提问by Newbie

So is this even possible? If i some day wanted to sprintf(str, "%doodle %d", var);output "%doodle 123" and not "123oodle", how can i stop the first %d from being processed?

那么这可能吗?如果有一天我想sprintf(str, "%doodle %d", var);输出“%doodle 123”而不是“123oodle”,我该如何停止处理第一个 %d?

回答by Brian R. Bondy

%% escapes the %

%% 转义 %