ACE_TString 是 ACE 对 c-string 的封装类,基本用起来了 std::string 差不多。
/* String_Base.h */
template <class CHAR> class ACE_String_Base { ... };
/* SStringfwd.h */
typedef ACE_String_Base<char> ACE_CString;
typedef ACE_String_Base<ACE_WSTRING_TYPE> ACE_WString;
// This allows one to use W or C String based on the Unicode
// setting
#if defined (ACE_USES_WCHAR)
typedef ACE_WString ACE_TString;
#else /* ACE_USES_WCHAR */
typedef ACE_CString ACE_TString;
#endif /* ACE_USES_WCHAR */
--------------------------------------------------------
#include <ace/Log_Msg.h>
#include <ace/SString.h>
int ACE_MAIN(char, ACE_TCHAR *[])
{
ACE_TString s1("hello"); // null-terminated string
ACE_TString s2("hello", 3); // lengthed string
ACE_TString s3(s2); // ACE_TString
ACE_TString s4(10, 'k'); // 10 of char 'k'
ACE_TString s5 = s1;
ACE_DEBUG((LM_DEBUG, ACE_TEXT("s1 = %s\n"), s1.c_str()));
ACE_DEBUG((LM_DEBUG, ACE_TEXT("s2 = %s\n"), s2.c_str()));
ACE_DEBUG((LM_DEBUG, ACE_TEXT("s3 = %s\n"), s3.c_str()));
ACE_DEBUG((LM_DEBUG, ACE_TEXT("s4 = %s\n"), s4.c_str()));
ACE_DEBUG((LM_DEBUG, ACE_TEXT("s5 = %s\n"), s5.c_str()));
ACE_DEBUG((LM_DEBUG, ACE_TEXT("s1[0] = %c, s1[1] = %c\n"), s1[0], s1[1]));
ACE_DEBUG((LM_DEBUG, ACE_TEXT("s1 == \"hello\", %d\n"), s1 == ACE_TEXT("hello")));
ACE_DEBUG((LM_DEBUG, ACE_TEXT("length(s1) = %d\n"), s1.length()));
ACE_DEBUG((LM_DEBUG, ACE_TEXT("hash(s1) = %d\n"), s1.hash()));
ACE_DEBUG((LM_DEBUG, ACE_TEXT("substr(s1, offset, length) = %s, %s\n"),
s1.substr(2).c_str(), s1.substr(2,2).c_str()));
ACE_DEBUG((LM_DEBUG, ACE_TEXT("find(s1, \"ll\") = %d\n"), s1.find(ACE_TEXT("ll"))));
return 0;
}
--------------------------------------------------------
s1 = hello
s2 = hel
s3 = hel
s4 = kkkkkkkkkkk
s5 = hello
s1[0] = h, s1[1] = e
s1 == "hello", 1
length(s1) = 5
hash(s1) = 94366051
substr(s1, offset, length) = llo, ll
find(s1, "ll") = 2
--------------------------------------------------------
评论