StringRef str = "Hello, world!"; std::cout << str.size() << std::endl; // Output: 13 std::cout << str[0] << std::endl; // Output: H
std::string s = "The quick brown fox jumps over the lazy dog"; StringRef str(s); std::cout << str.substr(16, 3) << std::endl; // Output: foxIn this example, we create a std::string object and initialize it with a long string. We then create a StringRef that references the std::string. We use the substr() method of the StringRef to extract the substring "fox". The StringRef class is part of the LLVM Support library.