std::string str = "Hello World"; for(auto it = str.cbegin(); it != str.cend(); ++it){ std::cout << *it << " "; }
std::string str = "My name is John"; auto it = str.cbegin(); std::cout << *it << std::endl; ++it; std::cout << *it << std::endl; ++it; std::cout << *it << std::endl;This example uses the `cbegin()` function to get a constant iterator to the beginning of the string. It then uses the iterator to access and print the first three characters of the string. Package/Library: C++ Standard Library.