C++解决:不存在从 “std::string” 到 “LPCWSTR” 的适当转换函数
@TOCC++解决:不存在从 “std::string” 到 “LPCWSTR” 的适当转换函数
解决办法如下:
//orig为输入的string字符串#include <string>
#include <iostream>
#include<cstdlib>
typedef const wchar_t* LPCWSTR;//#include<winnt.h>
using namespace std;
LPCWSTR stringToLPCWSTR(string orig)
{size_t origsize = orig.length() + 1;const size_t newsize = 100;size_t convertedChars = 0;wchar_t* wcstring = new wchar_t[sizeof(wchar_t) * (orig.length() - 1)];mbstowcs_s(&convertedChars, wcstring, origsize, orig.c_str(), _TRUNCATE);return wcstring;
}
int main()
{string in= "this is a txt!";LPCWSTR out = stringToLPCWSTR(in);wcout << out << endl;//别忘了释放内存~delete out;out = nullptr;return 0;
}
结果如图:
C++解决:不存在从 “std::string” 到 “LPCWSTR” 的适当转换函数相关推荐
- 错误 不存在从 “std::string“ 到 “LPCSTR“ 的适当转换函数
遇到这样的问题需要将std:string类型转为LPCSTR类型. 标准库的std::string转换成LPCSTR很简单:直接调用c_str()即可.例: std::string a="a ...
- 小白提问:C++ 不存在从 “std::string“ 到 “char *“ 的适当转换函数
提问 看不懂错误,把char nam[ ]换成string,strcpy(name1, nam)换成name1= nam就可以(我知道为什么可以,不知道为什么不可以@TOC #include #inc ...
- std::string中的find_first_of()和find_last_of()函数
编程语言: c++/linux 在std::string中,有时需要找到一个string中最后一个或者第一个以某个特定的字符开始的位置或者下标,这时就需要使用find_first_of()和find_ ...
- std::string格式化输入输出
在C语言中: C函数有sprintf函数, 比较方便, 但是需要知道所需要的内存空间是多少. 在C++的框架MFC中: 在MFC中CString 有Format函数来格式化字符串. 很方便. 难过的是 ...
- 几种C++ std::string和std::wstring相互转换的转换方法
第一种方法:调用WideCharToMultiByte()和MultiByteToWideChar(),代码如下(关于详细的解释,可以参考<windows核心编程>): #include ...
- C++11 - std::string - stod/stof/stoi/stol/stold/stoll/stoul/stoull
文章目录 1 std::stod 2 std::stof 3 std::stoi 4 std::stol 5 std::stold 6 std::stoll 7 std::stoul 8 std::s ...
- 【已解决】[Error] cannot pass objects of non-trivially-copyable type ‘std::string {aka class std::basic_s
[Error] cannot pass objects of non-trivially-copyable type 'std::string {aka class std::basic_string ...
- 解决C/C++报错error: cannot pass objects of non-trivially-copyable type ‘std::string’问题
目录 1.问题描述 2.原因分析 3.解决方法 1.问题描述 运行程序时,编译报错: error: cannot pass objects of non-trivially-copyable type ...
- 关于std::string 在 并发场景下 __grow_by_and_replace free was not allocated 的异常问题
使用string时发现了一些坑. 我们知道stl 容器并不是线程安全的,所以在使用它们的过程中往往需要一些同步机制来保证并发场景下的同步更新. 应该踩的坑还是一个不拉的踩了进去,所以还是记录一下吧. ...
最新文章
- PS多形式的部分之间复制“笨办法”
- 【剑指offer-Java版】24二叉搜索树后序遍历序列
- 对集合使用Comparator
- python函数必背知识点_必背函数——python学习第四次总结
- mysql导入创建表空间_oracle创建表空间 导入数据库
- (转)oracle表分区详解
- hdu 3549 最大流(EK实现)
- 将公司的主要项目从eclipse迁移到android studio for mac环境(1)
- 面试官:CountDownLatch 与 CyclicBarrier 的使用场景?有什么区别?
- luogu P1375 小猫
- mac 回车键、空格键失灵(非物理原因)解决方法
- 【转载】Altera FPGA使用通用SPI Flash(代替EPCS的方法)
- 2019美国大学计算机本科排名,美国大学计算机排名2019最新排名
- 台式计算机强制关机,台式机如何强制关机
- linux redhat 去掉警报声音
- 解决ubuntu无法解析域名、无网络连接问题
- PeopleSoft如何配置SMTP邮件服务
- 红米5双清_红米5刷recovery教程_红米5第三方中文recovery下载
- sshpass命令的安装使用
- redisHyperLogLog原理解析