#include#include int main() { std::string str = "Hello World"; // Using iterator to traverse the string for (auto it = str.begin(); it != str.end(); ++it) { std::cout << *it << " "; } return 0; }
#includeOutput: `dlroW olleH` In conclusion, the `begin()` function is a package library feature of the `std::basic_string` class template in C++. It returns an iterator to the beginning of the string, which can be used for various operations such as traversing or reversing a string.#include int main() { std::string str = "Hello World"; // Reversing the string by iterating from end to begin for (auto it = str.end() - 1; it >= str.begin(); --it) { std::cout << *it; } return 0; }