+ 1

How do i store the length of a string in a variable?

In cpp

30th Dec 2020, 10:30 AM
Aamir Kanhoush
Aamir Kanhoush - avatar
3 Answers
+ 5
Blazinghelmet int len = str.length()
30th Dec 2020, 10:35 AM
A͢J
A͢J - avatar
+ 1
Choose either one, a little note, all three are unsigned integer types. Where `auto` means compiler deduce the type of <len>. std::string::size_type len {your_string.size()}; Or std::size_t len {your_string.size()}; Or auto len {your_string.size()};
30th Dec 2020, 10:42 AM
Ipang
+ 1
#include<string.h> ... int i = strlen(your string);
30th Dec 2020, 10:45 AM
Muzammil
Muzammil - avatar