CSimpleStringT::operator PCXSTR

CSimpleStringT 对象存储的直接访问字符.作为c样式字符串。

operator PCXSTR( ) const throw( );

返回值

对字符串数据的一个字符的指针。

备注

字符不会复制;仅指针返回。 此运算符小心。 如果更改 CString 对象,在获得的字符指针后,可能导致无效指针内存的重新发布。

示例

下面的示例演示如何使用 CSimpleStringT::operator PCXSTR

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

CSimpleString strSports(L"Soccer is Best!", pMgr);
WCHAR sz[1024];

wcscpy_s(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 swprintf_s() needs the cast:

swprintf_s(sz, 1024, L"I think that %s!\n", (PCWSTR)strSports);

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

swprintf_s(sz, 1024, strSports);

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

wcout << strSports;

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

wcout << (PCWSTR)strSports;   

要求

Header: atlsimpstr.h

请参见

参考

CSimpleStringT选件类