当前位置:网站首页>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中发布的,现在看来这组宏具有
边栏推荐
- Redis主从、哨兵、集群模式介绍
- Visual upper system design and development (Halcon WinForm) -4 Communication management
- Concurrency-02-visibility, atomicity, orderliness, volatile, CAS, atomic class, unsafe
- Atlas atlas torque gun USB communication tutorial based on mtcom
- Using notepad++ to build an arbitrary language development environment
- Functional modules and application scenarios covered by the productization of user portraits
- Matplotlib drawing label cannot display Chinese problems
- 第04章_逻辑架构
- What is machine reading comprehension? What are the applications? Finally someone made it clear
- 北京共有产权房出租新规实施的租赁案例
猜你喜欢

What are the composite types of Blackhorse Clickhouse, an OLAP database recognized in the industry

Influxdb2 sources add data sources

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

C语言刷题~Leetcode与牛客网简单题

mysql innodb 存储引擎的特性—行锁剖析

Popular understanding of gradient descent

第04章_逻辑架构

整形和浮点型是如何在内存中的存储
![[set theory] inclusion exclusion principle (complex example)](/img/9a/db5a75e27516378c31531773a8a221.jpg)
[set theory] inclusion exclusion principle (complex example)

Kubernetes will show you from beginning to end
随机推荐
[combinatorics] combinatorial identities (recursive combinatorial identities | sum of variable terms | simple combinatorial identities and | sum of variable terms | staggered sums of combinatorial ide
函数栈帧的创建和销毁
驱动与应用程序通信
Jvm-03-runtime data area PC, stack, local method stack
Construction of operation and maintenance system
XWiki Installation Tips
Visual upper system design and development (Halcon WinForm) -4 Communication management
【pytorch学习笔记】Datasets and Dataloaders
Digital image processing -- popular understanding of corrosion and expansion
Matplotlib drawing label cannot display Chinese problems
Kubernetes advanced training camp pod Foundation
Redis lock Optimization Practice issued by gaobingfa
XWiki安装使用技巧
Summary of concurrent full knowledge points
Win10 enterprise 2016 long term service activation tutorial
Halcon and WinForm study section 2
socket. IO build distributed web push server
[attention mechanism] [first vit] Detr, end to end object detection with transformers the main components of the network are CNN and transformer
视觉上位系统设计开发(halcon-winform)-3.图像控件
开启 Chrome 和 Edge 浏览器多线程下载