Logo

Programming-Idioms

History of Idiom 169 > diff from v54 to v55

Edit summary for version 55 by anonymous:
New Cpp implementation by user [anonymous]

Version 54

2019-02-01, 06:33:54

Version 55

2019-09-26, 15:27:04

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.

Illustration

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.

Illustration
Extra Keywords
size characters chars number runes
Extra Keywords
size characters chars number runes
Imports
#include <string>
Code
std::string s{ "my string" };
auto numberOfChars = s.size();
Comments bubble
s.size() and s.length() is the same
Doc URL
https://en.cppreference.com/w/cpp/string/basic_string/size