当前位置:网站首页>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中发布的,现在看来这组宏具有
边栏推荐
- GCC cannot find the library file after specifying the link library path
- Nppexec get process return code
- Kubernetes 进阶训练营 Pod基础
- 驱动与应用程序通信
- Puppet自动化运维排错案例
- Visual upper system design and development (Halcon WinForm) -5 camera
- Analysis of development mode process based on SVN branch
- Explanation of time complexity and space complexity
- Tensorflow realizes verification code recognition (III)
- [combinatorics] combinatorial identities (recursive combinatorial identities | sum of variable terms | simple combinatorial identities and | sum of variable terms | staggered sums of combinatorial ide
猜你喜欢
The markdown file obtains the pictures of the network and stores them locally and modifies the URL
qt使用QZxing生成二维码
Idea does not specify an output path for the module
Concurrency-01-create thread, sleep, yield, wait, join, interrupt, thread state, synchronized, park, reentrantlock
Jvm-03-runtime data area PC, stack, local method stack
Popular understanding of ovo and ovr
视觉上位系统设计开发(halcon-winform)-3.图像控件
Kubernetes will show you from beginning to end
【云原生训练营】模块八 Kubernetes 生命周期管理和服务发现
Introduction to redis master-slave, sentinel and cluster mode
随机推荐
Final review points of human-computer interaction
驱动与应用程序通信
High quality workplace human beings must use software to recommend, and you certainly don't know the last one
el-switch 赋值后状态不变化
What are the composite types of Blackhorse Clickhouse, an OLAP database recognized in the industry
Kubernetes advanced training camp pod Foundation
使用Tengine解决负载均衡的Session问题
GCC cannot find the library file after specifying the link library path
Concurrency-01-create thread, sleep, yield, wait, join, interrupt, thread state, synchronized, park, reentrantlock
App全局异常捕获
Using notepad++ to build an arbitrary language development environment
Detailed comments on MapReduce instance code on the official website
The first character of leetcode sword offer that only appears once (12)
Custom annotation
mysql innodb 存储引擎的特性—行锁剖析
Calibre LVL
The markdown file obtains the pictures of the network and stores them locally and modifies the URL
Jvm-09 byte code introduction
Analysis of development mode process based on SVN branch
秒杀系统3-商品列表和商品详情