c++ - 模板函数中的 itoa

标签 c++ templates itoa

代码先行:

template <typename T>
void do_sth(int count)
{
    char str_count[10];
    //...
    itoa(count, str_count, 10);
    //...
}

但是我遇到了这样的编译错误:

error: there are no arguments to ‘itoa’ that depend on a template parameter, so a declaration of ‘itoa’ must be available
error: ‘itoa’ was not declared in this scope

但我确实包括了<cstdlib> . 谁能告诉我哪里出了问题?

最佳答案

itoa 似乎是一个非标准函数,并非在所有平台上都可用。请改用 snprintf(或类型安全的 std::stringstream)。

关于c++ - 模板函数中的 itoa,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7461451/

相关文章:

c++ - 检测类是否具有带签名的构造函数

c - atoi 是标准函数。但 itoa 不是。为什么?

C++菜鸟: how can I store code for a class in helper/auxiliary files,却还能访问所有类成员函数?

c++ - 匹配别名模板作为模板参数

c++ - 将 Variadic 模板包转换为 std::initializer_list

c++ - 替代 itoa() 将整数转换为字符串 C++?

c - 我必须下载哪个库才能在 C 中获取 itoa()

c++ - 与调用函数相比,goto 语句是否有效?

c++ - 如何在 Qt 中以编程方式调整拆分器小部件的大小?

c++ - 对象反射