如何在C ++中将std :: string转换为LPCWSTR?
在本节中,我们将看到如何将C++宽字符串(std::wstring)转换为LPCWSTR。LPCWSTR是(指向恒定宽度STRing的长指针)。它基本上是带有宽字符的字符串。因此,通过将宽字符串转换为宽字符数组,我们可以获得LPCWSTR。该LPCWSTR是Microsoft定义的。因此,要使用它们,我们必须在程序中包含Windows.h头文件。
要将std::wstring转换为宽字符数组类型的字符串,我们可以使用名为c_str()的函数将其变为类似于字符串的C并指向宽字符串。
范例程式码
#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;
}输出结果
my_str is : Hello World Wide String is : Hello World
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿