(int i = 0; i < strlen(char*); i++) throwing warning?

I'm getting a Visual Studio Warning for the following statement

1
2
3
4
5
  m_plate[9]
  std::cin >> m_plate;
  for (int i = 0; i < strlen(m_plate); i++){
      ....
  }


Is throwing this error?

warning C4018: '<': signed/unsigned mismatch


Any solutions to get rid of this? is strlen not a viable option to use when doing for loops?

strlen returns a size_t variable which can be used for loops and such as I seen here [link]https://stackoverflow.com/questions/2550774/what-is-size-t-in-c#:~:text=size_t%20is%20an%20unsigned%20integer%20data%20type%20which%20can%20assign,you%20can%20run%20the%20programm.[/link]
The size_t type is unsigned, but you are comparing a signed int to unsigned, which generates a compiler warning because it can lead to hard-to-spot bugs in general.

You could change your int to be size_t so that it matches the return type of strlen.
perfect thanks.
Topic archived. No new replies allowed.