Partager via


CFixedStringT Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at CFixedStringT Class.

This class represents a string object with a fixed character buffer.

Syntax

template<class StringType, int t_nChars>
class CFixedStringT : private CFixedStringMgr, public StringType

Parameters

StringType
Used as the base class for the fixed string object and can be any CStringT-based type. Some examples include CString, CStringA, and CStringW.

t_nChars
The number of characters stored in the buffer.

Members

Public Constructors

Name Description
CFixedStringT::CFixedStringT The constructor for the string object.

Public Operators

Name Description
CFixedStringT::operator = Assigns a new value to a CFixedStringT object.

Remarks

This class is an example of a custom string class based on CStringT. Although quite similar, the two classes differ in implementation. The major differences between CFixedStringT and CStringT are:

  • The initial character buffer is allocated as part of the object and has size t_nChars. This allows the CFixedString object to occupy a contiguous memory chunk for performance purposes. However, if the contents of a CFixedStringT object grows beyond t_nChars, the buffer is allocated dynamically.

  • The character buffer for a CFixedStringT object is always the same length ( t_nChars). There is no limitation on buffer size for CStringT objects.

  • The memory manager for CFixedStringT is customized such that sharing of a CStringData object between two or more CFixedStringT objectsis not allowed. CStringT objects do not have this limitation.

For more information on the customization of CFixedStringT and memory management for string objects in general, see Memory Management and CStringT.

Inheritance Hierarchy

IAtlStringMgr

StringType

CFixedStringMgr

CFixedStringT

Requirements

Header: cstringt.h

CFixedStringT::CFixedStringT

Constructs a CFixedStringT object.

CFixedStringT() throw();
explicit CFixedStringT(IAtlStringMgr* pStringMgr) throw();
CFixedStringT(const CFixedStringT<StringType, t_nChars>& str);
CFixedStringT(const StringType& str);
CFixedStringT(const StringType::XCHAR* psz);
explicit CFixedStringT(const StringType::YCHAR* psz);
explicit CFixedStringT(const unsigned char* psz);

Parameters

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

str
An existing CFixedStringT object to be copied into this CFixedStringT object.

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

Remarks

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.

CFixedStringT::operator =

Reinitializes an existing CFixedStringT object with new data.

CFixedStringT<StringType, t_nChars>& operator=(
  const CFixedStringT<StringType, t_nChars>& str);
CFixedStringT<StringType, t_nChars>& operator=(const char* psz);
CFixedStringT<StringType, t_nChars>& operator=(const wchar_t* psz);
CFixedStringT<StringType, t_nChars>& operator=(const unsigned char* psz);
CFixedStringT<StringType, t_nChars>& operator=(const StringType& str);

Parameters

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

psz
An existing CFixedStringT to be copied into this CFixedStringT object.

Remarks

You should be aware that memory exceptions may occur whenever you use the assignment operator because new storage is often allocated to hold the resulting CFixedStringT object.

See Also

CStringT Class
Hierarchy Chart
ATL/MFC Shared Classes