有什么方法可以将const char *转换为int?

时间:2020-06-02 14:32:31

标签: c++ casting

我对C ++还是陌生的,还不了解所有规则。我正在尝试通过从int返回const char *来修复此功能。看起来像这样:

int UARTwrite(const char *pcBuf, uint32_t ui32Len)
{
    const char* p = pcBuf;
    int i = 0;
    for( i = 0; i < ui32Len; ++i )
    {
        printf( "%c", *p );
        ++p;
    }
    return(std::cout << p << ' ' << static_cast<int> (p)); // error: invalid static_cast from type 'const char*' to type 'int'
}

在没有退货之前,所以我尝试了一个static_cast,但没有成功。我评论了错误不断弹出。任何帮助表示赞赏。

0 个答案:

没有答案