代码优先:

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/

10-09 07:14