Logo

Programming-Idioms

History of Idiom 169 > diff from v85 to v86

Edit summary for version 86 by programming-idioms.org:
Admin deletes impl 4429: Doesn't properly handle multibyte characters

Version 85

2020-12-28, 22:37:03

Version 86

2020-12-28, 22:37:45

Idiom #169 String length

Assign to integer n the number of characters of string s.
Make sure that multibyte characters are properly handled.
n can be different from the number of bytes of s.

Idiom #169 String length

Assign to integer n the number of characters of string s.
Make sure that multibyte characters are properly handled.
n can be different from the number of bytes of s.

Variables
n,s
Variables
n,s
Extra Keywords
size characters chars number runes
Extra Keywords
size characters chars number runes
Code
int n = s.size();
Comments bubble
Returns byte count if s is of type std::string, for other character widths use a different specialization of std::basic_string
Doc URL
https://en.cppreference.com/w/cpp/string/basic_string/size