#include#include using namespace std; int main() { string str = "hello world"; // find the index of the letter 'l' int pos = str.indexOf('l'); cout << "Index of 'l': " << pos << endl; // find the index of the substring 'wor' pos = str.indexOf("wor"); cout << "Index of 'wor': " << pos << endl; // if the letter or substring is not found, indexOf returns -1 pos = str.indexOf('z'); cout << "Index of 'z': " << pos << endl; return 0; }
Index of 'l': 2 Index of 'wor': 6 Index of 'z': -1It is likely that the `indexOf` function is part of the standard library for C++, since it is used frequently for string manipulation.