Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
The std::string class provides a rich set of member functions to manipulate and analyze text data.
length() / size()Returns the number of characters in the string.
append(str) / +=Adds text to the end of the string.
substr(pos, len)Returns a part of the string starting at 'pos'.
find(str)Returns the index of the first occurrence of 'str'.
clear()Removes all characters from the string.
empty()Checks if the string length is 0.
string s = "C++ Programming";
if (s.find("Prog") != string::npos) {
string sub = s.substr(4, 4); // "Prog"
cout << sub.length(); // 4
}string::npos is a constant returned by find() if the substring is not found.