-1

I try to setup a simple access control mechanism in Arduino and C++. The single password for access is known at compilation time and looks something like this

const unsigned int PASSWORD[] = {1, 2, 3, 4, 5};

To compare the user input with PASSWORD, I need several other arrays (not all of them with the same data type) that have the same number of elements as PASSWORD.

At the moment, the only way I can think of to achieve this is to have a second constant variable

const unsigned int PASSWORD_LENGTH = 5;

However, having the user enter a password and the same password's length in the settings seems like an unnecessary redundancy to me.

Therefore, my question is, if there is a way to inform the compiler about PASSWORD's length and to use this length as a variable in the code, without having the user counting the elements herself?

speendo
  • 13,045
  • 22
  • 71
  • 107

1 Answers1

0

You can use std::size().

This will help : https://en.cppreference.com/w/cpp/iterator/size

RammerChoi
  • 99
  • 6