#include#include int main() { std::string str = "hello world"; for (auto it = str.begin(); it != str.cend(); ++it) { std::cout << *it << " "; } return 0; }
#includeIn this example, we use the cend function to obtain an iterator pointing to one past the end of the string "abcdefg". We then decrement the iterator to obtain an iterator to the last character of the string, and print it to the console. Package/Library: Standard C++ Library.#include int main() { std::string str = "abcdefg"; auto it = str.cend(); --it; std::cout << "The last character of the string is: " << *it << std::endl; return 0; }