why strlen isn't working here????please help me | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

why strlen isn't working here????please help me

https://code.sololearn.com/ca3a9a15445A ./Playground/file0.cpp: In function 'int main()': ./Playground/file0.cpp:13:16: error: cannot convert 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'const char*' 13 | cout<<strlen(str)<<endl; | ^~~ | | | std::string {aka std::__cxx11::basic_string<char>} In file included from ../Playground/++/10.2.0/cstring:42, from ./Playground/file0.cpp:3: ../Playground/:384:35: note: initializing argument 1 of 'size_t strlen(const char*)' 384 | extern size_t strlen (const char *__s) | ~~~~~~~~~~~~^~~

19th May 2021, 5:59 AM
saurabh
saurabh - avatar
3 Antworten
+ 2
It's because *str* is of type std::string and strlen() works on C style strings ( char * or char[] ) Use str.length() to get desired results https://code.sololearn.com/c1FwiNcRqTGs/?ref=app
19th May 2021, 6:30 AM
Arsenic
Arsenic - avatar
0
Error what i am getting pasted in description... Please look in to it and please help me
19th May 2021, 6:04 AM
saurabh
saurabh - avatar
0
Arsenic thanks bro.....
19th May 2021, 6:47 AM
saurabh
saurabh - avatar