LPSTR a = LPSTR("hello"); how to convert a to LPCWSTR? string in C++ are confusing me, why methods use LPCWSTR and not just LPSTR D: I hope someone can provide a link where I can learn C++ strings
Asked
Active
Viewed 351 times
0
-
2Does this answer your question? [how to convert from LPCSTR to LPCWSTR in c++](https://stackoverflow.com/questions/8044506/how-to-convert-from-lpcstr-to-lpcwstr-in-c) – Renat Apr 12 '21 at 08:30
-
i will check that link out – Crazy Simon Apr 12 '21 at 08:59
-
@Renat _lpa is undefined – Crazy Simon Apr 12 '21 at 09:04
-
On Windows, LPSTR is char*, LPCWSTR is wchar_t*. Answer here: [How to convert char* to wchar_t*?](https://stackoverflow.com/questions/8032080/how-to-convert-char-to-wchar-t) – holmes0 Apr 12 '21 at 09:26
1 Answers
1
LPSTR
and LPCWSTR
are Windows specific types. They are not c++ strings, but char pointers alias which are C.
The STL - Standard Template Library - which is shipped with C++ provides a std::string
class, which is a convinient alias for basic_string<char, std::char_traits<char>, std::allocator<char>>
. See the documentation here.
-
-
@Crazy Simon https://www.learncpp.com/cpp-tutorial/an-introduction-to-stdstring/ – Emanuel P Apr 12 '21 at 09:20
-
-
-
@CrazySimon That's because the STL support different kinds of strings, i.e. plain ASCII bytes and wide characters for Unicode. `basic_string` is a template that gets instantiated with types that describe the kind of character. But this is not relevant for a beginner; you can just use `std::string`. – Emanuel P Apr 13 '21 at 06:49