是否有任何 C 标准函数将值"1"传递给所有 (%s)
Is there any C standard function to pass a value "1" to all (%s)
我只想知道是否有任何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 个参数。
No.
没有C标准函数。 至于C++(因为你说 cpp 函数(,我不确定,但我非常怀疑它是否存在。
不,标准中没有这样的东西。另请查看此和此以获取更多信息。
您将不得不寻找执行此操作的库。
例如,在C++中,这可能是提升:
#include <boost/format.hpp>
int main ()
{
std::cout << boost::format("%1%.%1%.%2%") % 12 % 2014 << 'n';
}
输出12.12.2014
不!但是您可以创建自己的函数,该函数接收数字字符串并将其放入%s...
相关文章:
- 编译器如何在使用SFINAE的函数和标准函数之间确定两者是否可行
- 如何使用模板化标准::函数作为参数?
- 是否有任何 C 标准函数将值"1"传递给所有 (%s)
- 可变参数模板和标准::函数
- 是否有一个标准函数可以打印/监视stdin文件的内容,同时将数据留在stdin中
- 我怎样才能把这个标准::函数传递给标准::异步
- 如何使用标准::函数使用可变参数模板
- "AfxIsValidAddress"函数的等效标准函数是什么?
- 使用多个参数将成员功能指针转换为标准C函数
- C++:将标准::函数转换为gsl_function
- 标准::函数的 typename 关键字
- 将成员函数作为标准函数回调
- C++在全局命名空间中找不到非标准 C 函数
- 标准函数的函数指针和成员函数指针的规则是什么
- 如何使用数组创建标准::函数
- 如何在 Visual Studio 中测试时重写标准C++函数
- 在C++中使用标准 C 函数时,是否需要"std::"前缀?
- 链接器如何查找标准函数和WinAPI函数
- 标准::函数复制参数
- 互斥与标准函数调用