nsAString str; str.AssignLiteral("Hello World!");
void printString(nsAString& str){ printf("String: %S\n", str.BeginReading()); } int main(){ nsAString str; str.AssignLiteral("This is a test string."); printString(str); return 0; }In this example, the AssignLiteral function is used to assign the string literal "This is a test string." to the nsAString variable str. The function printString takes an nsAString reference and outputs the string using printf. The output of this program would be: "String: This is a test string." Package library: Mozilla Gecko SDK.