#includeTPtrC myString = _L("Hello World"); // initialize TPtrC with a constant string TInt length = myString.Length(); // get the length of the string for (TInt i = 0; i < length; i++) { // loop through each character in the string TChar c = myString[i]; // get the character at index i // do something with c... }
#includeIn this example, we define a function called `someFunction` which takes a constant reference to a TPtrC object as a parameter. Inside the function, we can manipulate the TPtrC object without modifying its contents. We then create a buffer containing a string and initialize a TPtrC object called `constString` with the buffer. Finally, we pass `constString` as a parameter to the `someFunction` function. This code also uses the Symbian OS package library `e32std.h`.void someFunction(const TPtrC& aString) { // do something with the TPtrC object aString... } int main() { TBuf<100> buf(_L("some string")); // create a buffer containing a string TPtrC constString = buf; // initialize TPtrC with the buffer someFunction(constString); // pass the TPtrC object as a parameter to a function //... }