void printString(CStrRef str) { std::cout << str << std::endl; } int main() { const char* message = "Hello, world!"; printString(message); // no copy of message is made }
CStrRef name = "Alice"; std::cout << name.length() << std::endl; // prints 5 std::cout << name[0] << std::endl; // prints 'A' std::cout << name.substr(1, 3) << std::endl; // prints "lic"In this example, we create a CStrRef object representing the string "Alice". We can then call various string methods on the CStrRef object, such as length(), which returns the length of the string, and substr(), which returns a substring of the original string. These examples use CStrRef from the PHP-CPP library, which is a C++ library for building PHP extensions. CStrRef is used extensively in PHP-CPP to represent PHP strings passed as arguments to C++ functions.