Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is a PWSTR and why use this naming compared to char*, std::string, or CString in C++?

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

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

like image 699
Brian T Hannan Avatar asked Jan 19 '10 20:01

Brian T Hannan


People also ask

What is a Pwstr?

a PWSTR would be a wchar_t string pointer. That is a UNICODE (usually UCS2) string with each character taking 16 bits. a char* would be a pointer 8 bits per character. this could be ASCII, ANSI, UTF8, or one of many hundreds of other encodings.

What is the difference between string and Cstring in C++?

What's different with <string>, <cstring> in C++? The cstring header provides functions for dealing with C-style strings — null-terminated arrays of characters. This includes functions like strlen and strcpy. It's the C++ version of the classic string.

What is a char * in C++?

char* is typically used to iterate through a character array, i.e., a C string. It is rarely used as a pointer to a single char, unlike how other pointers are typically used. C++ has newer constructs for strings that typically should be used.

Is char * Same as string?

char is a primitive data type whereas String is a class in java. char represents a single character whereas String can have zero or more characters. So String is an array of chars.


1 Answers

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

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.

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.

like image 137
John Knoeller Avatar answered Oct 05 '22 17:10

John Knoeller