当前位置:网站首页>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
边栏推荐
- 详解指针进阶2
- redis单线程问题强制梳理门外汉扫盲
- Dataframe returns the whole row according to the value
- 运维体系的构建
- leetcode_ Power of Four
- Can‘t connect to MySQL server on ‘localhost‘
- SQL server installation location cannot be changed
- Baidu AI Cloud helps Shizuishan upgrade the smart health care model of "Internet + elderly care services"
- Custom annotation
- Visual upper system design and development (Halcon WinForm) -6 Nodes and grids
猜你喜欢
Visual upper system design and development (Halcon WinForm) -3 Image control
视觉上位系统设计开发(halcon-winform)-3.图像控件
Redis cache penetration, cache breakdown, cache avalanche solution
视觉上位系统设计开发(halcon-winform)-1.流程节点设计
Solve the problem that pushgateway data will be overwritten by multiple push
qt使用QZxing生成二维码
[set theory] inclusion exclusion principle (complex example)
Jvm-08-garbage collector
视觉上位系统设计开发(halcon-winform)
需要知道的字符串函数
随机推荐
Nppexec get process return code
Kubernetes 进阶训练营 Pod基础
驱动与应用程序通信
Visual upper system design and development (Halcon WinForm) -5 camera
What are the composite types of Blackhorse Clickhouse, an OLAP database recognized in the industry
Tensorflow realizes verification code recognition (III)
Qt常用语句备忘
What is machine reading comprehension? What are the applications? Finally someone made it clear
QT use qzxing to generate QR code
[probably the most complete in Chinese] pushgateway entry notes
Matlab r2011b neural network toolbox precautions
Puppet自动化运维排错案例
【云原生训练营】模块八 Kubernetes 生命周期管理和服务发现
详解指针进阶1
视觉上位系统设计开发(halcon-winform)-3.图像控件
Mysql报错:[ERROR] mysqld: File ‘./mysql-bin.010228‘ not found (Errcode: 2 “No such file or directory“)
Visual host system design and development (Halcon WinForm)
如何使用 @NotNull等注解校验 并全局异常处理
Dataframe returns the whole row according to the value
[combinatorial mathematics] binomial theorem and combinatorial identity (binomial theorem | three combinatorial identities | recursive formula 1 | recursive formula 2 | recursive formula 3 Pascal / Ya