#include#include int main() { std::string str = "Hello, world!"; for (auto it = str.begin(); it != str.end(); ++it) { std::cout << *it; } return 0; }
#includeIn the above example, StringRef.end() is used to find the end of the string, then substracting the pointer to the beginning of the string from it gives the length of the string. Package Library: LLVM (llvm/ADT/StringRef.h)#include int main() { std::string str = "Hello, world!"; int len = str.end() - str.begin(); std::cout << "The length of the string is: " << len << '\n'; return 0; }