当前位置:网站首页>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中发布的,现在看来这组宏具有
边栏推荐
- 【可能是全中文网最全】pushgateway入门笔记
- 如何使用 @NotNull等注解校验 并全局异常处理
- 【Transformer】入门篇-哈佛Harvard NLP的原作者在2018年初以逐行实现的形式呈现了论文The Annotated Transformer
- What is embedding (encoding an object into a low dimensional dense vector), NN in pytorch Principle and application of embedding
- Incluxdb2 buckets create database
- Matlab r2011b neural network toolbox precautions
- Visual upper system design and development (Halcon WinForm) -3 Image control
- Digital image processing -- popular Canny edge detection
- MySQL reports an error: [error] mysqld: file '/ mysql-bin. 010228‘ not found (Errcode: 2 “No such file or directory“)
- leetcode_ Power of Four
猜你喜欢

Digital image processing -- popular Canny edge detection

Jvm-06-execution engine

Halcon and WinForm study section 2

High quality workplace human beings must use software to recommend, and you certainly don't know the last one

Visual upper system design and development (Halcon WinForm) -3 Image control
![[probably the most complete in Chinese] pushgateway entry notes](/img/5a/6dcb75f5d713ff513ad6842ff53cc3.png)
[probably the most complete in Chinese] pushgateway entry notes

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

The state does not change after the assignment of El switch

Halcon与Winform学习第一节

Jvm-09 byte code introduction
随机推荐
Summary of JVM knowledge points
需要知道的字符串函数
Tensorflow realizes verification code recognition (I)
视觉上位系统设计开发(halcon-winform)-3.图像控件
百度智能云助力石嘴山市升级“互联网+养老服务”智慧康养新模式
详解指针进阶2
Kubernetes vous emmène du début à la fin
[transform] [NLP] first proposed transformer. The 2017 paper "attention is all you need" by Google brain team
"Seven weapons" in the "treasure chest" of machine learning: Zhou Zhihua leads the publication of the new book "machine learning theory guide"
Jvm-06-execution engine
Functional modules and application scenarios covered by the productization of user portraits
Dataframe returns the whole row according to the value
Solve the problem that pushgateway data will be overwritten by multiple push
基础SQL教程
Halcon and WinForm study section 2
[daily training] 395 Longest substring with at least k repeated characters
Baidu AI Cloud helps Shizuishan upgrade the smart health care model of "Internet + elderly care services"
秒杀系统2-Redis解决分布式Session问题
Apache ant extension tutorial
Second kill system 3 - list of items and item details