gpt4 book ai didi

c++ - 是否有任何 C 标准函数可以将值 "1"传递给 all (%s)

转载 作者:行者123 更新时间:2023-11-30 19:57:10 24 4
gpt4 key购买 nike

我只是想知道是否有任何 C(或 C++)标准函数将值“1”传递给所有(%s)。

sprintf(buffer, "record_id(%s)record_num(%s)record_val (%s"), "1"));

而不是像这样传递并重复“1”:

sprintf(query_buffer, "record_id(%s)record_num(%s)record_val (%s"), "1", "1", "1"));

最佳答案

我认为你可以这样格式化它;

sprintf( buffer, "record_id(%s)record_num(%1$s)record_val (%1$s"), "1") );

这是 printf 的 POSIX 扩展格式字符串。您可以使用 n$ 来指示列表中的第 n 个参数。

关于c++ - 是否有任何 C 标准函数可以将值 "1"传递给 all (%s),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52207509/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com