In standard C++ applications, string literals are composed of ASCII characters. However, NGWS objects and applications cannot handle standard ASCII strings. Managed Extensions for C++ solves this problem by allowing string literals to be assigned to a variable of type System::String without casting.
String *s1 = "a string literal"; String *s2 = L"a wide string literal";
Managed Extensions support a new type of string literal (prefixed by S) that has type String* and better performance than a C++ string literal.
Note String literals prefixed by S are stored as single-byte characters. This is not the case with string literals prefixed by L, which are stored as double-byte characters.
In addition, all instances of identical string literals (prefixed by S) always point to the same object. This is not true for String* objects constructed from C++ string literals. The following example demonstrates this by comparing the pointer values of two instances (parm_s
and loc_s
) of the same string literal:
#using <mscorlib.dll> #include “assert.h” void MyFunction(String* parm_s) { String* loc_s = S"a NGWS frameworks string literal"; assert( parm_s == loc_s ); // String pointers are identical } void main() { String *s = S"a NGWS frameworks string literal"; MyFunction(s); };