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.

 to (L-1).
Overwriting the terminating '\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.

wstring to wchar_t*的更多相关文章

  1. 深入理解c++中char*与wchar_t*与string以及wstring之间的相互转换 [转]

    本篇文章是对c++中的char*与wchar_t*与string以及wstring之间的相互转换进行了详细的分析介绍,需要的朋友参考下. #ifndef USE_H_ #define USE_H_ # ...

  2. 深入理解c++中char*与wchar_t*与string以及wstring之间的相互转换

    本篇文章是对c++中的char*与wchar_t*与string以及wstring之间的相互转换进行了详细的分析介绍,需要的朋友参考下-复制代码 代码如下:    #ifndef USE_H_     ...

  3. C++ wstring string char* wchar_t相互转换

    标签: stringwstringwchar_tcharc++2013-12-19 00:29 3721人阅读 评论(0) 收藏 举报本文章已收录于: C++知识库 分类: C/C++(50) 1. ...

  4. wchar_t内置还是别名?小问题一则(升级公司以前代码遇到的问题)

    问题: 原来的2008工程用2010编译后,运行程序出现无法定位程序输入点 *@basic_string@_WU@*和*@basic_string@G@* 解决: 关闭“语言选项”中“将WChar_t ...

  5. wchar_t是内置还是别名(亲测有效:wchar_t在windows下是16位整数的别名,在linux等平台下是32位整数的别名。MSVC2008开始默认是/Zc:wchar_t)

    接前一篇C++ ABI之名字改编(以Qt为例),继续看看C++名字改编相关的问题. 问题 MSVC 有一对选项/Zc:wchar_t- 与 /Zc:wchar_t控制wchar_t 于是 wchar_ ...

  6. c++ wchar_t 与char 直接的转换【转】

    http://blog.163.com/tianshi_17th/blog/static/4856418920085209414977/ 实现了一下 #include "stdafx.h&q ...

  7. 对std::string和std::wstring区别的解释,807个赞同,有例子

    807down vote string? wstring? std::string is a basic_string templated on a char, and std::wstring on ...

  8. string与wstring的互相转换接口(Windows版本)

    string与wstring的互相转换接口(Windows版本) std::wstring stringToWstring( const std::string & str ) { LPCST ...

  9. VC++ 比较两个字符串是否相等,字母大小写相关。

    1.strcmp 这是用于ANSI标准字符串的函数(如string和char *),此函数接受两个字符串缓冲区做为参数,如果两个字符串是相同的则返回零.否则若第一个传入的字符串的值大于第二个字符串返回 ...

随机推荐

  1. bzoj 3669 lct维护最小生成树

    大概题意:给一个无向图,有a,b两种边权,找一条从1到n的路径,使得max(a[i])+max(b[i])最小a[i],b[i]表示该路径上的边的对应权. 如果用类似最短路的DP来做,显然每个点的状态 ...

  2. C#高级编程9-第7章 运算符和类型强制转换

    运算符和类型强制转换 1.运算符 运算符的简化操作 条件运算符: if-else的简化操作,也称三元运算符.如果条件为真,返回一个值,为假返回另外一个值. condition?true_value:f ...

  3. linux命令-每天一点进步

    2018-05-28 1.yum install -y,这里的-y表示,在安装软件的过程中,无需用户输入yes or no,默认yes 2../sbin/nginx -s reload,重启nginx ...

  4. curl多文件上传

    发送: header('Content-type:text/html; charset=utf-8'); //声明编码//模拟批量POST上传文件$url = 'http://test.cm/rece ...

  5. 解决Arcgis10.2.2中dbf文件用EXCEL打开乱码问题

    1.开始 -- 运行,输入”Regedit“,打开 注册表 . 2.如是用的是 10.x 版本 ArcGIS Desktop,定位到 ‘计算机\HKEY_CURRENT_USER\Software\E ...

  6. Arcgis Runtime for andriod 100 Simple marker symbol

    GraphicsOverlay graphicsOverlay = new GraphicsOverlay(); 58 mMapView.getGraphicsOverlays().add(graph ...

  7. DevExpress RichEditControl 上下翻页功能 z

    /// <summary> /// 翻页 /// </summary> /// <param name="isPre"></param&g ...

  8. 转: 用 Go 写一个轻量级的 ldap 测试工具

    前言 这是一个轮子. 作为一个在高校里混的 IT,LDAP 我们其实都蛮熟悉的,因为在高校中使用 LDAP 来做统一认证还蛮普遍的.对于 LDAP 的管理员而言,LDAP 的各种操作自然有产品对应的管 ...

  9. Mac 安装 brew

    安装方法:命令行输入 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/ma ...

  10. 通过http请求传递xml流和接收xml流的代码示例

    通过http请求传递xml流和接收xml流的代码示例 //1.在servlet中post一个xml流:import java.io.OutputStreamWriter;import org.jdom ...