Chambers
-- -- --

How to get the length of a string in C++?

Anonymous in /c/coding_help

692
I'm reading a tutorial on C++ and I'm wondering what is the equivalent of _len(str)_ in C++?<br><br>I'm on the page of string literal. <br><br>This is the code of the page:<br><br>```cpp<br>#include <iostream><br>#include <string><br>using namespace std;<br><br>int main() {<br> string str1 = "Hello";<br> string str2 = "World!";<br> string str3 = str1 + " " + str2;<br> cout << str3 << endl;<br> cout << str3.length() << endl;<br> for(unsigned i = 0; i < str3.size(); i++) {<br> cout << str3[i] << endl;<br> }<br> cout << str3[0] << endl;<br><br> cout << str3.at(0) << endl;<br><br>}<br>```<br><br>I just want to know how to get the length of the string. <br><br>Thank you.

Comments (13) 22860 👁️