当前位置:网站首页>Under VC, Unicode and ANSI are converted to each other, cstringw and std:: string are converted to each other
Under VC, Unicode and ANSI are converted to each other, cstringw and std:: string are converted to each other
2022-07-03 15:26:00 【Yulong_】
Preface
as everyone knows ,CString There are two kinds of , They are using ANSI Coded CStringA And use Unicode Coded CStringW, among CStringA and std::string The transformation of is very simple , After all, they are used ANSI code , Let's not talk about it here , Only talk CStringW and std::string The transformation of .
Text
Microsoft has provided wide and narrow byte conversion API function , But it's a little troublesome , Here is Microsoft in ATL Several macros provided in , It's very easy to use . The following conversion macros are commonly used :
1、W2A and A2W
2、CW2A and CA2W
One 、W2A and A2W How to use :
#include <atlconv.h>
#include <atlstr.h>
int main(int argc, _TCHAR* argv[])
{
// Use W2A and A2W when , This macro is required
USES_CONVERSION;
CStringW strw = L"Hello World";
//Unicode turn ANSI Use W2A
std::string strstd = W2A(strw);
//ANSI turn Unicode Use A2W
strw = A2W(strstd.c_str());
return 0;
}Before using this set of macros, you need to use USES_CONVERSION macro , This set of macros was developed by Microsoft in its early days ATL3.0 Released in , Now it seems This set of macros has
边栏推荐
- Didi off the shelf! Data security is national security
- Kubernetes - yaml file interpretation
- Atlas atlas torque gun USB communication tutorial based on mtcom
- [cloud native training camp] module 7 kubernetes control plane component: scheduler and controller
- Halcon and WinForm study section 1
- 基础SQL教程
- Puppet自动化运维排错案例
- 视觉上位系统设计开发(halcon-winform)-5.相机
- 找映射关系
- 整形和浮点型是如何在内存中的存储
猜你喜欢

Unity功能——Unity离线文档下载及使用

Detailed pointer advanced 2

What is embedding (encoding an object into a low dimensional dense vector), NN in pytorch Principle and application of embedding

Baidu AI Cloud helps Shizuishan upgrade the smart health care model of "Internet + elderly care services"

视觉上位系统设计开发(halcon-winform)

秒杀系统2-Redis解决分布式Session问题

How are integer and floating-point types stored in memory

基础SQL教程

Visual host system design and development (Halcon WinForm)

Can‘t connect to MySQL server on ‘localhost‘
随机推荐
Jvm-02-class loading subsystem
通过进程PID获取可执行文件路径(QueryFullProcessImageName)
视觉上位系统设计开发(halcon-winform)-5.相机
Finally, someone explained the financial risk management clearly
C language brush questions ~leetcode and simple questions of niuke.com
自定义注解
Detailed pointer advanced 2
PyTorch crop images differentiablly
视觉上位系统设计开发(halcon-winform)-6.节点与宫格
Basic SQL tutorial
从 flask 服务端代码自动生成客户端代码 -- flask-native-stubs 库介绍
Seckill system 3- product list and product details
XWiki Installation Tips
Kubernetes - yaml file interpretation
How are integer and floating-point types stored in memory
Jvm-09 byte code introduction
Jvm-05-object, direct memory, string constant pool
CString在多线程中的问题
运维体系的构建
Detailed comments on MapReduce instance code on the official website