首页 > 其他 > 详细

自定义字符类

时间:2018-06-13 12:52:28      阅读:151      评论:0      收藏:0      [点我收藏+]

   当 VC不使用MFC,无法使用属于MFC的CString,为此自定义一个,先暂时使用,后续完善。

头文件:

#pragma once

#define MAX_LOADSTRING 100 // 最大字符数

class CString
{
  public:
      
      char *c_str; 
      WCHAR *w_str;

      void operator = (const char *str); // = 操作,获得c字符串: str = "sss"; 式样
      void operator + (const CString str); // + 操作,获得s字符串加: s1 = s2 + s3; 式样
      void operator += (const CString str); // += 操作,获得s字符串加: s1 += "s2"; 式样

      int StrCount(void);// 返回字符串长度s.StrCount()
  
      CString(void);

  private:

      char cSAr[MAX_LOADSTRING];
      WCHAR wSAr[MAX_LOADSTRING];

      int iStrCount; // 字符串数量
};

C文件:

#include "stdafx.h"
#include "String.h"

CString::CString(void)
{
    c_str = cSAr;
    w_str = wSAr;
}

void CString::operator = (const char *str) // =
{
    int i;

    if(str == NULL) return;
    iStrCount = strlen(str);//获取字符串长度
    for(i = 0; i < iStrCount; i++)
       {
          cSAr[i] = str[i];
          wSAr[i] = str[i];
       }
    cSAr[i] = 0;
    wSAr[i] = 0;
}

void CString::operator + (const CString str) // +
{
     //
}

void CString::operator += (const CString str) // +=
{
  //
}

int CString::StrCount(void)
{
    return iStrCount;
}

 

自定义字符类

原文:https://www.cnblogs.com/hbg200/p/9176945.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!