Logo

Programming-Idioms

History of Idiom 169 > diff from v64 to v65

Edit summary for version 65 by Blooser:
[Cpp] Store length in variable

Version 64

2019-09-26, 22:03:03

Version 65

2019-09-26, 22:12:27

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 <iterator>
#include <string>
Imports
#include <iterator>
#include <string>
Code
std::cout<<std::distance(str.begin(), str.end());
Code
int n = std::distance(str.begin(), str.end());