⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringex.txt

📁 C++ patterns设计模式
💻 TXT
字号:
宏定义的意义说明:

SS_NO_REFCOUNT - By #define-ing this flag you effectively turn off reference counting for most assignment functions.  This is not perfect:  It only affects assignments done through CStdString.  Any assignments done through basic_string will still exhibit whatever reference counting behavior your basic_string implementation uses.  However it is a decent and efficient stop-gap solution to threading problems with the MS implemention. 

SS_NO_CONVERSION - This macro prevents StdString.h from defining any of the Unicode/MBCS conversion macros and functions.  If  you have trouble integrating the class in an MFC or ATL build, try #define-ing this flag. 

SS_STANDALONE - I usually comment out checks for this macro.  I use it in my own builds to allow me to export this class (with no changes) from a utiltity DLL I use.  If you get build errors about the compiler not being able to find "w32base.h", just #define this (or rip out the offending line).  I usually comment out this check before posting a CStdString update on my website, but every once in a while, I forget. 

SS_INC_COMDEF - You should not define this macro.  It simply tells the rest of the StdString code that <comdef.h> was included earlier.  

SS_ANSI - If you build CStdString on non-Win32 platforms, or with compilers other than Visual C++, or with implementations of the Standard C++ Library besides that provided with Visual C++, then this macro must be defined.  Otherwise you may define if you wish to limit the CStdString code to use on Standard C++ library functions

This macro prevents the StdString.h header from using any Win32 specific or Visual C++ specific functions that it otherwise would.  I use these functions under Win32 for performance improvements and to provide a full CString facade to the class.  However they are not necessary.  The StdString.h header should be able to automatically #define SS_ANSI when it is needed.   However it does not alway work so you may need to #define it yourself

SS_USE_FACET - Makes up for the non-standard nature of the DinkumWare implementation of std::use_facet<>.

I intend to one more that will let you: 

1. Force all IStream-related code to pack the CStdStringWs (the wchar_t-based version) into CStdStringAs (the char-based version) before streaming.  I've seen this help if you stream a LOT of strings and don't have too much bandwidth. 


使用方法举例:

// You can add just about any form of string to a CStdString
// with operator+()
CStdString strVal1(_T("THIS IS A STRING   "));
OutputDebugString(strVal1 + _T("\n"));
strVal1 += _bstr_t(" plus a BSTR string");
strVal1 += '.' < /P> 

// Some conversion functions can be chained together

strVal1.ToLower().TrimRight();

// Case INsensitive comparison via Equals() or CompareNoCase()

strVal1 = _T("THIS IS A STRING")
CStdString strVal2(_T("thIs Is a sTRing"));
_ASSERTE(strVal1 != strVal2);
_ASSERTE(strVal1.Equals(strVal2));
_ASSERTE(strVal1.CompareNoCase(strVal2) == 0);


// Format() works just like CString's

strVal1.Format(_T("This %s a string named strVal%d"), _T("IS"), 1);
OutputDebugString(strVal1 + _T("\n"));


// Declare an STL map class which maps strings to integers.  The
// keys are case insensitive, so an integer stored under the key
// _T("MYKEY") could be retrieved with the value _T("mykey")

typedef std::map<CStdString, int, StdStringLessNoCase> CMyMap
CMyMap myMap;
myMap[_T("MYKEY")] = 7;
_ASSERTE(myMap.find(_T("mykey")) != myMap.end());


// If this were MFC code, we could serialize the strings to CArchives:

void  CMyObject::Serialize(CArchive& ar)
{
    CStdString strVal3(_T("This is a string"));
    if ( ar.IsStoring() )
        ar << strVal;
    else
        ar >> strVal;
}

// If we were implementing the IPersistStream interface on a COM
// object which had a member CStdString variable named 'm_strVal',
// we could take advantage of the CStdString stream functions to
// greatly simplify the implementation as follows:

HRESULT CMyComObject::GetSizeMax(ULARGE_INTEGER* pcbSizeMax)
{
    pcbSizeMax->QuadPart = m_strVal.StreamSize();
    return S_OK;
}
HRESULT CMyComObject::Save(IStream* pStream, BOOL bClearDirty)
{
    return m_strVal.StreamSave(pStream);
}
HRESULT CMyComObject::Load(IStream* pStream)
{
    return m_strVal.StreamLoad(pStream);
}

// If we were calling some windows function that fills out a
// buffer for us we can use the GetBuffer() function.  .

CStdString strPath;
::GetTempPath(strPath.GetBuffer(MAX_PATH+1), MAX_PATH);
strPath.ReleaseBuffer();

// You can set the resource handle for loading string resources
// and then load them via either the constructor or the Load()
// function.

CStdString::SetResourceHandle(::GetModuleHandle(NULL));
CStdString strString(IDS_STRING1);
strString.Load(IDS_STRING2)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -