By Michi Ariovist


2019-08-13 19:50:20 8 Comments

Here is the code:

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));
        }
    }

I don't know why he throws this error for "digits.push_back(atoi(c))".

I'm a very beginner, I know this will be not that difficult for you.

2 comments

@Jeffrey 2019-08-13 19:53:56

You can't do:

atoi(c)

atoi() expects a char *. You probably want

digits.push_back(c - '0');

@Mark Ransom 2019-08-13 19:54:33

The function atoi() takes a single const char * type as a parameter.

You're calling it with a char parameter. The compiler doesn't know how to convert from one to the other.

atoi actually wants a string as input, you can't call it with a single character. A string always needs a zero character as a terminator.

@Michi Ariovist 2019-08-13 19:58:46

thats pretty funny, when it comes to the task, I should solve it with atoi(). Maybe i understood it completely wrong. Thanks!

Related Questions

Sponsored Content

9 Answered Questions

[SOLVED] Meaning of 'const' last in a function declaration of a class?

1 Answered Questions

15 Answered Questions

[SOLVED] How can I convert a std::string to int?

  • 2011-10-05 15:23:45
  • Brandon
  • 1198578 View
  • 413 Score
  • 15 Answer
  • Tags:   c++ string int

12 Answered Questions

[SOLVED] Storing C++ template function definitions in a .CPP file

  • 2008-09-22 15:55:52
  • Rob
  • 296133 View
  • 458 Score
  • 12 Answer
  • Tags:   c++ templates

8 Answered Questions

[SOLVED] How to convert a std::string to const char* or char*?

  • 2008-12-07 19:30:56
  • user37875
  • 872679 View
  • 849 Score
  • 8 Answer
  • Tags:   c++ string char const

24 Answered Questions

[SOLVED] Image Processing: Algorithm Improvement for 'Coca-Cola Can' Recognition

10 Answered Questions

4 Answered Questions

[SOLVED] error: passing xxx as 'this' argument of xxx discards qualifiers

  • 2011-05-12 04:52:56
  • JASON
  • 363236 View
  • 396 Score
  • 4 Answer
  • Tags:   c++

3 Answered Questions

[SOLVED] invalid conversion from 'const char*' to 'char*'

  • 2014-01-07 23:34:25
  • user2333234
  • 122290 View
  • 35 Score
  • 3 Answer
  • Tags:   c++

2 Answered Questions

Sponsored Content