+ 1

Difference between string length and string size

What is the difference between string length and string size?

15th Dec 2017, 5:16 PM
RR2001
RR2001 - avatar
2 odpowiedzi
+ 3
if you do: string s = "abc"; int size = s.size(); int len = s.length(); cout << size << len; you will still get 3 in "size" integer and the same in "len" integer. they can do practically same thing but it's more recommend to do length() since it's more readable and size() is used in vectors
15th Dec 2017, 5:34 PM
Roabs
Roabs - avatar
+ 1
@Jamie So basically string size also includes null character \0 correct?
15th Dec 2017, 5:32 PM
RR2001
RR2001 - avatar