Closed. This question is not reproducible or was caused by typos。它当前不接受答案。












想改善这个问题吗?更新问题,以便将其作为on-topic用于堆栈溢出。

1年前关闭。



Improve this question




这是代码:
bool Vehicle::checkID(std::string id)
{
    std::vector<int> digits;

    for (char c : id)
    {
        if(std::isdigit(c))
        {
            digits.push_back(atoi(c));
        }

        else
        {
            digits.push_back(int(c));
        }
    }

我不知道他为什么会为“digits.push_back(atoi(c))”抛出此错误。

我是一个初学者,我知道这对您来说并不难。

最佳答案

您不能:

atoi(c)
atoi()需要一个char *。你可能想要
digits.push_back(c - '0');

10-07 19:01
查看更多