次の方法で共有


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;   

必要条件

**ヘッダー:**atlsimpstr.h

参照

参照

CSimpleStringT クラス

その他の技術情報

CSimpleStringT のメンバー