c++ string转lpcwstr
时间: 2023-10-24 10:30:30 浏览: 258
要将C++的string类型转换为LPCWSTR类型,可以使用下面的方法:
1. 使用wstring和wcscpy_s函数进行转换。首先,将string类型的字符串转换为wstring类型的字符串,然后再使用wcscpy_s函数将wstring类型的字符串复制到LPCWSTR类型的缓冲区中。代码如下所示:
```cpp
std::wstring stringToLPCWSTR(const std::string& orig) {
size_t origsize = orig.size() + 1;
size_t convertedChars = 0;
wchar_t* wcstring = new wchar_t<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [C++类型转换 string 转 LPCWSTR](https://blog.csdn.net/sylsjane/article/details/80868496)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [实战c++中的string系列--string到LPCWSTR的转换](https://blog.csdn.net/wangshubo1989/article/details/50274103)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文