Logo

Programming-Idioms

History of Idiom 169 > diff from v82 to v83

Edit summary for version 83 by WHS:
New C++ implementation by user [WHS]

Version 82

2020-11-06, 09:13:54

Version 83

2020-12-24, 16:54:32

Idiom #169 String length

Assign to integer n the number of characters of string s.

This 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.

This 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 widths use a different specialization of std::basic_string
Doc URL
https://en.cppreference.com/w/cpp/string/basic_string/size