Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C++

Chuyển đổi std::string sang LPCWSTR trong C++


LPCWSTR (Long Pointer to Constant Wide String) dùng trong Windows API. Chuyển std::wstring sang LPCWSTR bằng c_str(). Cần include Windows.h.

Ví dụ

#include <iostream>
#include <Windows.h>
using namespace std;

int main() {
    wstring my_str = L"Hello World";
    LPCWSTR wide_string = my_str.c_str();
    wcout << "my_str is : " << my_str << endl;
    wcout << "Wide String is : " << wide_string << endl;
    return 0;
}

Kết quả

my_str is : Hello World
Wide String is : Hello World