CStringT::CStringT

Constructs a CStringT object.

CStringT( ) throw() : 
   CThisSimpleString(
      StringTraits::GetDefaultManager()
   );

explicit CStringT(
   IAtlStringMgr* pStringMgr
) throw() : 
   CThisSimpleString(
      pStringMgr
   );

CStringT(
   const VARIANT& varSrc
);

CStringT(
   const VARIANT& varSrc,
   IAtlStringMgr* pStringMgr
);

CStringT( 
  const CStringT& strSrc
) : 
   CThisSimpleString( 
      strSrc
   );

operator CSimpleStringT<
   BaseType,
   !_CSTRING_IMPL_::_MFCDLLTraitsCheck<
      BaseType,
      StringTraits
   >::   c_bIsMFCDLLTraits 
> &()

template <
   bool bMFCDLL
>
CStringT(
   const CSimpleStringT<
      BaseType,
      bMFCDLL
   > & strSrc
) : 
   CThisSimpleString(
      strSrc
);

template <
   class SystemString
>
CStringT(
   SystemString^ pString
) : 
   CThisSimpleString(
      StringTraits::GetDefaultManager()
   );

CStringT(
   const XCHAR* pszSrc
) : 
   CThisSimpleString(
      StringTraits::GetDefaultManager()
   );

CSTRING_EXPLICIT CStringT(
   const YCHAR* pszSrc
) : 
   CThisSimpleString(
      StringTraits::GetDefaultManager()
   );

CStringT(
   LPCSTR pszSrc,
   IAtlStringMgr* pStringMgr
) : 
   CThisSimpleString(
      pStringMgr
   );

CStringT(
   LPCWSTR pszSrc,
   IAtlStringMgr* pStringMgr
) : 
   CThisSimpleString(
      pStringMgr
);

CSTRING_EXPLICIT CStringT(
   const unsigned char* pszSrc
) : 
   CThisSimpleString(
      StringTraits::GetDefaultManager()
   );

/*CSTRING_EXPLICIT*/ CStringT(
   char* pszSrc
) : 
   CThisSimpleString(
      StringTraits::GetDefaultManager()
   );

CSTRING_EXPLICIT CStringT(
   unsigned char* pszSrc
) : 
   CThisSimpleString(
      StringTraits::GetDefaultManager()
   );

CSTRING_EXPLICIT CStringT(
   wchar_t* pszSrc
) : 
   CThisSimpleString(
      StringTraits::GetDefaultManager()
   );

CStringT(
   const unsigned char* pszSrc,
   IAtlStringMgr* pStringMgr
) : 
   CThisSimpleString(
      pStringMgr
   );

CSTRING_EXPLICIT CStringT(
   char ch,
   int nLength = 1
) : 
   CThisSimpleString(
      StringTraits::GetDefaultManager()
   );

CSTRING_EXPLICIT CStringT(
   wchar_t ch,
   int nLength = 1
) : 
   CThisSimpleString(
      StringTraits::GetDefaultManager()
   );

CStringT(
   const XCHAR* pch,
   int nLength
) : 
   CThisSimpleString(
      pch,
      nLength,
      StringTraits::GetDefaultManager()
   );

CStringT(
   const YCHAR* pch,
   int nLength
) : 
   CThisSimpleString(
      StringTraits::GetDefaultManager()
   );

CStringT(
   const XCHAR* pch,
   int nLength,
   IAtlStringMgr* pStringMgr
) : 
   CThisSimpleString(
      pch,
      nLength,
      pStringMgr
);

CStringT(
   const YCHAR* pch,
   int nLength,
   IAtlStringMgr* pStringMgr
) : 
   CThisSimpleString(
      pStringMgr
   );

pch

A pointer to an array of characters of length nLength, not null-terminated.

nLength

A count of the number of characters in pch.

ch

A single character.

pszSrc

A null-terminated string to be copied into this CStringT object.

pStringMgr

A pointer to the memory manager for the CStringT object. For more information on IAtlStringMgr and memory management for CStringT, see Memory Management with CStringT.

strSrc

An existing CStringT object to be copied into this CStringT object. For more information on CThisString and CThisSimpleString, see the Remarks section.

varSrc

A variant object to be copied into this CStringT object.

BaseType

The character type of the string class. Can be one of the following:

char (for ANSI character strings).

wchar_t (for Unicode character strings).

TCHAR (for both ANSI and Unicode character strings).

bMFCDLL

Boolean that specifies whether the project is an MFC DLL (TRUE) or not (FALSE).

SystemString

Must be System::String, and the project must be compiled with /clr.

pString

A handle for a CStringT object.

Because the constructors copy the input data into new allocated storage, you should be aware that memory exceptions may result. Note that some of these constructors act as conversion functions. This allows you to substitute, for example, an LPTSTR where a CStringT object is expected.

  • CStringT( LPCSTR lpsz ): Constructs a Unicode CStringT from an ANSI string. You can also use this constructor to load a string resource as shown in the example below.

  • CStringT( LPCWSTR  lpsz ): Constructs a CStringT from a Unicode string.

  • CStringT( const unsigned char* psz ): Allows you to construct a CStringT from a pointer to unsigned char.

Note Note

Define the _CSTRING_DISABLE_NARROW_WIDE_CONVERSION macro to turn off implicit string conversion between ANSI and Unicode strings. The macro excludes from compilation constructors that support conversion.

Note that the strSrc parameter can be either a CStringT or CThisSimpleString object. For CStringT, use one of its default instantiations (CString, CStringA, or CStringW); for CThisSimpleString, use a this pointer. CThisSimpleString declares an instance of the CSimpleStringT Class, which is a smaller string class with less built-in functionality than the CStringT class.

The overload operator CSimpleStringT<>&() constructs a CStringT object from a CSimpleStringT declaration.

Note Note

Although it is possible to create CStringT instances that contain embedded null characters, we recommend against it. Calling methods and operators on CStringT objects that contain embedded null characters can produce unintended results.

// typedef CStringT<TCHAR, StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>>> CAtlString;

CAtlString s1;                    // Empty string
CAtlString s2(_T("cat"));           // From a C string literal
CAtlString s3 = s2;               // Copy constructor
CAtlString s4(s2 + _T(" ") + s3);   // From a string expression

CAtlString s5(_T('x'));             // s5 = "x"
CAtlString s6(_T('x'), 6);          // s6 = "xxxxxx"

CAtlString s7((LPCSTR)ID_FILE_NEW); // s7 = "Create a new document"

VARIANT var;
V_VT(&var) = VT_BSTR;
V_BSTR(&var) = ::SysAllocString(L"Football is a fun sport.");
CAtlString s8(var); // s8 = "Football is a fun sport." 

// The following statement does not call the assignment operator. 
// The compiler considers the following statement equivalent to 
// CAtlString city("Paris")
CAtlString city = _T("Paris");   

Header: cstringt.h

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft