
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert std::string to LPCWSTR in C++
In this section we will see how to convert C++ wide string (std::wstring) to LPCWSTR. The LPCWSTR is the (Long Pointer to Constant Wide STRing). It is basically the string with wide characters. So by converting wide string to wide character array we can get LPCWSTR. This LPCWSTR is Microsoft defined. So to use them we have to include Windows.h header file into our program.
To convert std::wstring to wide character array type string, we can use the function called c_str() to make it C like string and point to wide character string.
Example Code
#include<iostream> #include<Windows.h> using namespace std; main(){ wstring my_str = L"Hello World"; LPCWSTR wide_string ; //define an array with size of my_str + 1 wide_string = my_str.c_str(); wcout << "my_str is : " << my_str <<endl; wcout << "Wide String is : " << wide_string <<endl; }
Output
my_str is : Hello World Wide String is : Hello World
Advertisements