博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
wstring to wchar_t*
阅读量:5838 次
发布时间:2019-06-18

本文共 1245 字,大约阅读时间需要 4 分钟。

 

If you want to convert from std::wstring to const WCHAR* (i.e. the returned pointer gives read-only access to the string content), then calling std::wstring::c_str() method is just fine:

std::wstring wstrProcToSearch;

std::wcin >> wstrProcToSearch; // input std::wstring

 

// Convert to const WCHAR* (read-only access)

const WCHAR * wpszProcToSearch = wstrProcToSearch.c_str();

Instead, if you want to modify std::wstring's content, things are different. You can use &wstr[0](where wstr is a non-empty instance of std::wstring) to access the content of the std::wstring(starting from the address of its first characters, and noting that characters are stored contiguously in memory), but you must pay attention to not overrun string's pre-allocated memory.

In general, if you have a std::wstring of length L, you can access characters from index 0 to (L-1).

'\0' (located at index L) is undefined behavior (in practice, it's OK on Visual C++, at least with VC9/VS2008 and VC10/VS2010).

If the string has not the proper size (i.e. it's not big enough for your needs), then you can call std::wstring::resize() to make room for new characters (i.e. resizing internal std::wstring's buffer), and then use &wstr[0] to read-write std::wstring's content.

转载地址:http://uajcx.baihongyu.com/

你可能感兴趣的文章
创业维艰、守成不易
查看>>
PHP环境安装套件:快速安装LAMP环境
查看>>
CSS3
查看>>
ul下的li浮动,如何是ul有li的高度
查看>>
C++ primer plus
查看>>
python mysqlDB
查看>>
UVALive 3942 Remember the Word Tire+DP
查看>>
从微软的DBML文件中我们能学到什么(它告诉了我们什么是微软的重中之重)~目录...
查看>>
被需求搞的一塌糊涂,怎么办?
查看>>
c_数据结构_队的实现
查看>>
jquery 选择器总结
查看>>
Qt设置背景图片
查看>>
【阿里云文档】常用文档整理
查看>>
java中的Volatile关键字
查看>>
前端自定义图标
查看>>
实验二
查看>>
独立开发一个云(PaaS)的核心要素, Go, Go, Go!!!
查看>>
网站文章如何能自动判定是抄袭?一种算法和实践架构剖析
查看>>
【OpenCV学习】滚动条
查看>>
ofo用科技引领行业进入4.0时代 用户粘性连续8个月远甩摩拜
查看>>