自定义字符类

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

头文件:

#pragma once#define MAX_LOADSTRING 100 // 最大字符数class CString
{public:char *c_str, cSAr[MAX_LOADSTRING];WCHAR *w_str,wSAr[MAX_LOADSTRING];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:int iStrCount; // 字符串数量void CharToWChar(const char *pChar);//窄字符转宽字符void WCharToChar(WCHAR *pWideChar);//宽字符转窄字符 
};

C文件:

#include "stdafx.h"
#include "String.h"CString::CString(void)
{c_str = cSAr;w_str = wSAr;
}void CString::operator = (const char *str) // =
{if(str == NULL) return;iStrCount = strlen(str);//获取字符串长度for(int i = 0; i < iStrCount; i++)//转内存储 cSAr[i] = str[i];cSAr[iStrCount] = 0;CharToWChar(str);//转宽字符
}void CString::operator + (const CString str) // +
{//
}void CString::operator += (const CString str) // +=
{//
}int CString::StrCount(void)
{return iStrCount;
}void CString::CharToWChar(const char *pChar)//窄字符转宽字符
{if(pChar == NULL) return;int needWChar = MultiByteToWideChar(CP_ACP, 0, pChar, -1, NULL, 0);if(needWChar > 0){ZeroMemory(wSAr, (needWChar + 1) * sizeof(WCHAR));MultiByteToWideChar(CP_ACP, 0, pChar, -1, wSAr, needWChar);}
}void CString::WCharToChar(WCHAR *pWideChar)//宽字符转窄字符  
{if(pWideChar == NULL) return;int needBytes = WideCharToMultiByte(CP_ACP, 0, pWideChar, -1, NULL, 0, NULL, NULL);if(needBytes > 0){ZeroMemory(cSAr, (needBytes + 1) * sizeof(char));WideCharToMultiByte(CP_ACP, 0, pWideChar, -1, cSAr, needBytes, NULL, NULL);}
}

 

转载于:https://www.cnblogs.com/hbg200/p/9176945.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/389447.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

使用python和javascript进行数据可视化

Any data science or data analytics project can be generally described with the following steps:通常可以通过以下步骤来描述任何数据科学或数据分析项目&#xff1a; Acquiring a business understanding & defining the goal of a project 获得业务理解并定义项目目…

Android 事件处理

事件就是用户对图形的操作&#xff0c;在android手机和平板电脑上&#xff0c;主要包含物理按键事件和触摸屏事件两类。物理按键事件包含&#xff1a;按下、抬起、长按等&#xff1b;触摸屏事件主要包含按下、抬起、滚动、双击等。 在View中提供了onTouchEvent()方法&#xff0…

莫烦Pytorch神经网络第三章代码修改

3.1Regression回归 import torch import torch.nn.functional as F from torch.autograd import Variable import matplotlib.pyplot as plt""" 创建数据 """x torch.unsqueeze(torch.linspace(-1,1,100),dim1) y x.pow(2) 0.2*torch.rand(x…

为什么饼图有问题

介绍 (Introduction) It seems as if people are split on pie charts: either you passionately hate them, or you are indifferent. In this article, I am going to explain why pie charts are problematic and, if you fall into the latter category, what you can do w…

New Distinct Substrings(后缀数组)

New Distinct Substrings&#xff08;后缀数组&#xff09; 给定一个字符串&#xff0c;求不相同的子串的个数。\(n<50005\)。 显然&#xff0c;任何一个子串一定是后缀上的前缀。先&#xff08;按套路&#xff09;把后缀排好序&#xff0c;对于当前的后缀\(S_i\)&#xff0…

Android dependency 'com.android.support:support-v4' has different version for the compile (26.1.0...

在项目中加入react-native-camera的时候 出现的错误. 解决方案: 修改 implementation project(:react-native-camera)为 implementation (project(:react-native-camera)) {exclude group: "com.android.support"}查看原文 Could not find play-services-basement.aa…

先知模型 facebook_使用Facebook先知进行犯罪率预测

先知模型 facebookTime series prediction is one of the must-know techniques for any data scientist. Questions like predicting the weather, product sales, customer visit in the shopping center, or amount of inventory to maintain, etc - all about time series …

莫烦Pytorch神经网络第四章代码修改

4.1CNN卷积神经网络 import torch import torch.nn as nn from torch.autograd import Variable import torch.utils.data as Data import torchvision import matplotlib.pyplot as pltEPOCH 1 BATCH_SIZE 50 LR 0.001 DOWNLOAD_MNIST False #如果数据集已经下载到…

github gists 101使代码共享漂亮

If you’ve been going through Medium, looking at technical articles, you’ve undoubtedly seen little windows that look like the below:如果您一直在阅读Medium&#xff0c;并查看技术文章&#xff0c;那么您无疑会看到类似于以下内容的小窗口&#xff1a; def hello_…

loj #6278. 数列分块入门 2

题目 题解 区间修改&#xff0c;询问区间小于c的个数。分块排序&#xff0c;用vector。至于那个块的大小&#xff0c;好像要用到均值不等式 我不太会。。。就开始一个个试&#xff0c;发现sizsqrt(n)/4时最快&#xff01;&#xff01;&#xff01;明天去学一下算分块复杂度的方…

基于Netty的百万级推送服务设计要点

1. 背景1.1. 话题来源最近很多从事移动互联网和物联网开发的同学给我发邮件或者微博私信我&#xff0c;咨询推送服务相关的问题。问题五花八门&#xff0c;在帮助大家答疑解惑的过程中&#xff0c;我也对问题进行了总结&#xff0c;大概可以归纳为如下几类&#xff1a;1&#x…

莫烦Pytorch神经网络第五章代码修改

5.1动态Dynamic import torch from torch import nn import numpy as np import matplotlib.pyplot as plt# torch.manual_seed(1) # reproducible# Hyper Parameters INPUT_SIZE 1 # rnn input size / image width LR 0.02 # learning rateclass…

鲜为人知的6个黑科技网站_6种鲜为人知的熊猫绘图工具

鲜为人知的6个黑科技网站Pandas is the go-to Python library for data analysis and manipulation. It provides numerous functions and methods that expedice the data analysis process.Pandas是用于数据分析和处理的Python库。 它提供了加速数据分析过程的众多功能和方法…

VRRP网关冗余

实验要求 1、R1创建环回口&#xff0c;模拟外网 2、R2&#xff0c;R3使用VRRP技术 3、路由器之间使用EIGRP路由协议  实验拓扑  实验配置  R1(config)#interface loopback 0R1(config-if)#ip address 1.1.1.1 255.255.255.0R1(config-if)#int e0/0R1(config-if)#ip addr…

网页JS获取当前地理位置(省市区)

网页JS获取当前地理位置&#xff08;省市区&#xff09; 一、总结 一句话总结&#xff1a;ip查询接口 二、网页JS获取当前地理位置&#xff08;省市区&#xff09; 眼看2014又要过去了&#xff0c;翻翻今年的文章好像没有写几篇&#xff0c;忙真的或许已经不能成为借口了&#…

大熊猫卸妆后_您不应错过的6大熊猫行动

大熊猫卸妆后数据科学 (Data Science) Pandas is used mainly for reading, cleaning, and extracting insights from data. We will see an advanced use of Pandas which are very important to a Data Scientist. These operations are used to analyze data and manipulate…

数据eda_关于分类和有序数据的EDA

数据eda数据科学和机器学习统计 (STATISTICS FOR DATA SCIENCE AND MACHINE LEARNING) Categorical variables are the ones where the possible values are provided as a set of options, it can be pre-defined or open. An example can be the gender of a person. In the …

PyTorch官方教程中文版:PYTORCH之60MIN入门教程代码学习

Pytorch入门 import torch""" 构建非初始化的矩阵 """x torch.empty(5,3) #print(x)""" 构建随机初始化矩阵 """x torch.rand(5,3)""" 构造一个矩阵全为 0&#xff0c;而且数据类型是 long &qu…

Flexbox 最简单的表单

弹性布局(Flexbox)逐渐流行&#xff0c;越来越多的人开始使用&#xff0c;因为它写Css布局真是太简单了一一、<form>元素表单使用<form>元素<form></form>复制代码上面是一个空的表单&#xff0c;根据HTML标准&#xff0c;它是一个块级元素&#xff0c…

CSS中的盒子模型

一.为什么使用CSS 1.有效的传递页面信息 2.使用CSS美化过的页面文本&#xff0c;使页面漂亮、美观&#xff0c;吸引用户 3.可以很好的突出页面的主题内容&#xff0c;使用户第一眼可以看到页面主要内容 4.具有良好的用户体验 二.字体样式属性 1.font-family:英…