0

For sure.. Condition

A valid username needs to be minimum 4, maximum 20 characters long. if(sizeof(name) >= 4 && sizeof(name) <= 20 ) Is true ?

24th Nov 2020, 2:53 AM
Mashael Alasmari
Mashael Alasmari - avatar
2 Réponses
+ 5
Sizeof returns the bytes in the string. You have to use .length() method... Like this For sure.. Condition if(name.length() >= 4 && name.length() <= 20 )
24th Nov 2020, 2:58 AM
Steve Sajeev
Steve Sajeev - avatar
+ 1
No, the sizeof() operator will return the size in bytes of memory the variable is. You could still use it to do some math and figure out how many chars name is though, but it's much easier to just get the length of the string. https://www.w3schools.com/cpp/cpp_strings_length.asp
24th Nov 2020, 3:02 AM
ChaoticDawg
ChaoticDawg - avatar