win32 UNICODE 支持


#include <string>

#ifdef _UNICODE
#define tstring std::wstring
#define __T(quote) L##quote
#else
#define tstring string
#define __T(quote) quote
#endif

#define _T(quote) __T(quote)   
#define _TEXT(quote) __T(quote) 
#define TEXT(quote) __T(quote)




                std::string T2A(const tstring& sInput)
                {
#ifdef _UNICODE
                                return std::string(sInput.begin(), sInput.end());
#else
                                return sInput;
#endif
                };

                tstring A2T(const std::string& sInput)
                {
#ifdef _UNICODE
                                return tstring(sInput.begin(), sInput.end());
#else
                                return sInput;
#endif
                };



int replace_all(tstring& str const tstring& pattern const tstring& newpat)
{
                int count = 0;
                const size_t nsize = newpat.size();
                const size_t psize = pattern.size();

                for(size_t pos = str.find(pattern, 0); 
                                pos != tstring::npos;
                                pos = str.find(pattern,pos + nsize))
                {
                                str.replace(pos, psize, newpat);
                                count++;
                }

                return count;
}
  
posted @ 2013-07-02 16:50  muzizongheng  阅读(336)  评论(0编辑  收藏  举报
如果我们时时忙着展现自己的知识, 将何从忆起成长所需的无知?