登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Code@Pig Home

喜欢背着一袋Code傻笑的Pig .. 忧美.欢笑.记忆.忘却 .之. 角落

 
 
 

日志

 
 

[ACE] ACE_TString  

2009-12-09 08:47:27|  分类: net_ACE |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
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
--------------------------------------------------------

  评论这张
 
阅读(3259)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018