Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

CSimpleStringT::operator PCXSTR 

Directly accesses characters stored in a CSimpleStringT object as a C-style string.

operator PCXSTR( ) const throw( );

A character pointer to the string's data.

No characters are copied; only a pointer is returned. Be careful with this operator. If you change a CString object after you have obtained the character pointer, you may cause a reallocation of memory that invalidates the pointer.

The following example demonstrates the use of CSimpleStringT::operator PCXSTR.

// If the prototype of a function is known to the compiler,
// the PCXSTR cast operator may be invoked implicitly.

CSimpleStringT strSports( _T ( "Soccer is Best!" ) );
TCHAR sz[1024];

lstrcpy( sz, strSports );

// If the prototype isn't known or is a va_arg prototype,
// you must invoke the cast operator explicitly. For example,
// the va_arg part of a call to sprintf( ) needs the cast:

sprintf( sz, "I think that %s!\n", ( PCXSTR ) strSports );

// While the format parameter is known to be an PCXSTR and
// therefore doesn't need the cast:

sprintf( sz, strSports );

// Note that some situations are ambiguous. This line will
// put the address of the strSports object to stdout:

cout << strSports;

// while this line will put the content of the string out:

cout << ( PCXSTR ) strSports;

Community Additions

© 2015 Microsoft