Strings
The string class handles text. Use length(), substr(), find(), append or +, replace and compare. Strings can be indexed with [] and changed, unlike strings in many languages.
Example
string s = "Hello, C++";
cout << s.length() << endl;
cout << s.substr(7) << endl;
cout << s.find("C++") << endl;
s[0] = 'J';
cout << s << endl;
cout << (string("a") + "b") << endl;
cout << (s == "Jello, C++") << endl;Result
10 C++ 7 Jello, C++ ab 1
Exercise
Get the number of characters.
s.()
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.