什么是PWSTR和为什么使用这个命名相比,char *,std :: string或CString在C ++? [英] What exactly is a PWSTR and why use this naming compared to char*, std::string, or CString in C++?

查看:1394
本文介绍了什么是PWSTR和为什么使用这个命名相比,char *,std :: string或CString在C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在各种c ++代码中,你经常看到不同的字符串用法:PWSTR,char *,std :: string,CString等...

In various c++ code you often see different usage of strings: PWSTR, char*, std::string, CString, etc ...

与任何其他字符串类型相比,使用PWSTR的时间?

When is the best time to use PWSTR as compared to any other string type?

推荐答案

PWSTR将是 wchar_t 字符串指针。这是一个UNICODE(通常是UCS2)字符串,每个字符采用16位。

a PWSTR would be a wchar_t string pointer. That is a UNICODE (usually UCS2) string with each character taking 16 bits.

a char * 将是每个字符8位的指针。这可以是ASCII,ANSI,UTF8或者其他几百种编码之一。虽然你只需要担心编码,如果你需要保存非英语或特殊符号的语言。

a char* would be a pointer 8 bits per character. this could be ASCII, ANSI, UTF8, or one of many hundreds of other encodings. Although you only need to worry about encodings if you need the string to hold languages other than English or special symbols.

一般来说,Windows API是内部的所有UNICODE,所以最Windows程序员使用wchar字符串。但 std :: string CString 都可以是UNICODE,如果正确的符号 #defined ,因此您在 PWSTR std :: string CString 将是一个偏好的问题或你使用的代码库的约定。

In general, The Windows API is all UNICODE internally so most Windows programmers use wchar strings. But std::string and CString can both be UNICODE if the right symbols are #defined, so your choice between PWSTR, std::string and CString will be a matter of preference or the convention of the codebase you work with.

这篇关于什么是PWSTR和为什么使用这个命名相比,char *,std :: string或CString在C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆