当前位置:网站首页>VC下Unicode和ANSI互转,CStringW和std::string互转
VC下Unicode和ANSI互转,CStringW和std::string互转
2022-07-03 15:20:00 【宇龍_】
前言
众所周知,CString有两种,分别是使用ANSI编码的CStringA和使用Unicode编码的CStringW,其中CStringA和std::string的转化非常简单,毕竟都是使用的ANSI编码,这里就不谈了,只谈CStringW和std::string的转化。
正文
微软有提供宽窄字节转换的API函数,但稍显麻烦了一些,这里使用的是微软在ATL中提供的几个宏,使用非常的简单。常用的有如下转换宏:
1、W2A和A2W
2、CW2A和CA2W
一、W2A和A2W的使用方法:
#include <atlconv.h>
#include <atlstr.h>
int main(int argc, _TCHAR* argv[])
{
//使用W2A和A2W时,需要使用该宏
USES_CONVERSION;
CStringW strw = L"Hello World";
//Unicode转ANSI使用W2A
std::string strstd = W2A(strw);
//ANSI转Unicode使用A2W
strw = A2W(strstd.c_str());
return 0;
}使用这组宏之前需要先使用USES_CONVERSION宏,这组宏是微软在早期的ATL3.0中发布的,现在看来这组宏具有
边栏推荐
- Kubernetes帶你從頭到尾捋一遍
- win32创建窗口及按钮(轻量级)
- How to use annotations such as @notnull to verify and handle global exceptions
- 解决pushgateway数据多次推送会覆盖的问题
- Visual upper system design and development (Halcon WinForm) -2 Global variable design
- 视觉上位系统设计开发(halcon-winform)-5.相机
- 官网MapReduce实例代码详细批注
- redis缓存穿透,缓存击穿,缓存雪崩解决方案
- Concurrency-02-visibility, atomicity, orderliness, volatile, CAS, atomic class, unsafe
- 使用Tengine解决负载均衡的Session问题
猜你喜欢

Incluxdb2 buckets create database
![[pytorch learning notes] datasets and dataloaders](/img/c0/9cd539caff34db3cccc44505bbe3c5.png)
[pytorch learning notes] datasets and dataloaders

Construction of operation and maintenance system

Jvm-02-class loading subsystem

The state does not change after the assignment of El switch

Basic SQL tutorial

Characteristics of MySQL InnoDB storage engine -- Analysis of row lock

Finally, someone explained the financial risk management clearly

Leasing cases of the implementation of the new regulations on the rental of jointly owned houses in Beijing

el-switch 赋值后状态不变化
随机推荐
Win10 enterprise 2016 long term service activation tutorial
北京共有产权房出租新规实施的租赁案例
[attention mechanism] [first vit] Detr, end to end object detection with transformers the main components of the network are CNN and transformer
Kubernetes - YAML文件解读
[Yu Yue education] scientific computing and MATLAB language reference materials of Central South University
视觉上位系统设计开发(halcon-winform)
秒杀系统1-登录功能
Tensorflow realizes verification code recognition (II)
详解指针进阶2
What is embedding (encoding an object into a low dimensional dense vector), NN in pytorch Principle and application of embedding
【pytorch学习笔记】Transforms
Tensorflow realizes verification code recognition (I)
The state does not change after the assignment of El switch
第04章_逻辑架构
【可能是全中文网最全】pushgateway入门笔记
[cloud native training camp] module 7 kubernetes control plane component: scheduler and controller
Jvm-04-runtime data area heap, method area
软件安装信息、系统服务在注册表中的位置
Relationship between truncated random distribution and original distribution
Visual host system design and development (Halcon WinForm)