std::string stores its data internally in the form of a null-terminated C-string, but in normal usage does not allow you to access the null terminator#include <string> => Header file to includestring variableName => Declare a stringstring variableName = "value" => Initialize a string, Giving it value, Spaces are allowedstring variableName(N, 'c') => Initialize a string filled with character 'c' n timescin >> variableName => Take input value of string without spacesgetline(cin, variableName); => Get whole line of inputcin.getline(variableName, N);variableName[N] => Access the (N-1)th charactervariableName.at(N) => Get character in stringvariableName.back() => Access last charactervariableName.front() => Access first charactervariableName.length() => Returns length of stringvariableName.size() => Returns length of stringvariableName.empty() => Returns true if string is emptyvariableName.clear() => Clear stringvariableName.max_size() => Return maximum size of stringvariableName.resize(N) => Resize string to "n"variableName.resize(N, 'val') => Resize string to "n" filling all values with character 'val'variableName.capacity() => Return size of allocated storagevariableName.push_back("value") => Append characters to stringvariableName.pop_back() => Delete last charactervariableName.insert(N, "value") => Insert value at the nth indexvariableName.erase(N, m) => Removes 'm' characters starting from nth indexvariableName1.append(variableName2) => Append s2 in the end of s1variableName1 + variableName2 => Append s2 in the end of s1variableName.replace() => Replace portion of stringvariableName1.swap(variableName2) => Exchange the values of these two string objectsvariableName.compare() => Compare stringsvariableName.substr(N) => Returns string starting from Nth indexvariableName.substr(N, M) => Returns 'M' characters starting from Nth index, util end of the string if it comes firstvariableName.find("value") => Returns the first index of the substring foundvariableName1.compare(variableName2) => Returns 0 if equal, Positive value if S1 is greaterstrlen(variableName) => Returns length of stringstrcmp(variableName1, variableName2) => Returns true if both array are equalstrcpy(variableName1, variableName2) => Copies variableName2 in variableName1to_string(variableName) => Converts an integer into a stringstoi(variableName) => Converts a string to integer values into an integerstoi(variableName, N, M) => N is starting position, M is base of number system, Default is 10atoi(variableName) => Converts a character array argument to integer valuetransform(N, m, o, ::tolower) => Transforms the string in lowercase, Parameters are start index, end index, where to starttransform(N, m, o, ::toupper) => Transforms the string in uppercasesort(N, m) => Sorts the characters in ascending, Parameter n is starting and m is ending indexsort(N, m, greater()) => Sorts the characters in descending, greater() function returns true when condition is validvariableName.begin() => Returns the first character of thr stringvariableName.end() => It returns an iterator pointing to the end of the stringvariableName.rbegin() => Return reverse iterator to reverse beginningvariableName.rend => Return reverse iterator to reverse end for (int i = 0; i < variableName.length(); ++i) {
char ch = variableName[i];
}
for (char ch : variableName) {
cout << ch;
}
for (string::iterator it = variableName.begin(); it != variableName.end(); ++it) {
char ch = *it;
}
for (string::const_iterator it = variableName.begin(); it != variableName.end(); ++it) {
char ch = *it;
}
stringstream variableName;variableName << value => Store string value into variableNamevariableName >> variableName2 => Store the value obtained from variableName which is now iterating through variableName into variableName2, Data type should be taken care ofvariableName.str() => Make string out of variableNamevariableName.eof()variableName.good()