当前位置:网站首页>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中发布的,现在看来这组宏具有
边栏推荐
- Leetcode the smallest number of the rotation array of the offer of the sword (11)
- socket.io搭建分布式Web推送服务器
- leetcode_ Power of Four
- 秒殺系統3-商品列錶和商品詳情
- 北京共有产权房出租新规实施的租赁案例
- [cloud native training camp] module VIII kubernetes life cycle management and service discovery
- Kubernetes带你从头到尾捋一遍
- Second kill system 3 - list of items and item details
- Popular understanding of ovo and ovr
- socket. IO build distributed web push server
猜你喜欢
"Seven weapons" in the "treasure chest" of machine learning: Zhou Zhihua leads the publication of the new book "machine learning theory guide"
Seckill system 3- product list and product details
Introduction to redis master-slave, sentinel and cluster mode
How to use annotations such as @notnull to verify and handle global exceptions
[transformer] Introduction - the original author of Harvard NLP presented the annotated transformer in the form of line by line implementation in early 2018
【pytorch学习笔记】Datasets and Dataloaders
运维体系的构建
详解指针进阶2
Popular understanding of ovo and ovr
What is embedding (encoding an object into a low dimensional dense vector), NN in pytorch Principle and application of embedding
随机推荐
【Transformer】入门篇-哈佛Harvard NLP的原作者在2018年初以逐行实现的形式呈现了论文The Annotated Transformer
XWiki Installation Tips
Kubernetes帶你從頭到尾捋一遍
Search in the two-dimensional array of leetcode sword offer (10)
redis单线程问题强制梳理门外汉扫盲
mysql innodb 存储引擎的特性—行锁剖析
Popular understanding of linear regression (I)
Global and Chinese market of air cargo logistics 2022-2028: Research Report on technology, participants, trends, market size and share
求字符串函数和长度不受限制的字符串函数的详解
SQL server installation location cannot be changed
阿特拉斯atlas扭矩枪 USB通讯教程基于MTCOM
Digital image processing -- popular understanding of corrosion and expansion
[cloud native training camp] module 7 kubernetes control plane component: scheduler and controller
Kubernetes - YAML文件解读
Chapter 04_ Logical architecture
【云原生训练营】模块八 Kubernetes 生命周期管理和服务发现
GCC cannot find the library file after specifying the link library path
官网MapReduce实例代码详细批注
Visual upper system design and development (Halcon WinForm) -5 camera
redis缓存穿透,缓存击穿,缓存雪崩解决方案