@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” 的适当转换函数相关推荐

  1. 错误 不存在从 “std::string“ 到 “LPCSTR“ 的适当转换函数

    遇到这样的问题需要将std:string类型转为LPCSTR类型. 标准库的std::string转换成LPCSTR很简单:直接调用c_str()即可.例: std::string a="a ...

  2. 小白提问:C++ 不存在从 “std::string“ 到 “char *“ 的适当转换函数

    提问 看不懂错误,把char nam[ ]换成string,strcpy(name1, nam)换成name1= nam就可以(我知道为什么可以,不知道为什么不可以@TOC #include #inc ...

  3. std::string中的find_first_of()和find_last_of()函数

    编程语言: c++/linux 在std::string中,有时需要找到一个string中最后一个或者第一个以某个特定的字符开始的位置或者下标,这时就需要使用find_first_of()和find_ ...

  4. std::string格式化输入输出

    在C语言中: C函数有sprintf函数, 比较方便, 但是需要知道所需要的内存空间是多少. 在C++的框架MFC中: 在MFC中CString 有Format函数来格式化字符串. 很方便. 难过的是 ...

  5. 几种C++ std::string和std::wstring相互转换的转换方法

    第一种方法:调用WideCharToMultiByte()和MultiByteToWideChar(),代码如下(关于详细的解释,可以参考<windows核心编程>): #include ...

  6. 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 ...

  7. 【已解决】[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 ...

  8. 解决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 ...

  9. 关于std::string 在 并发场景下 __grow_by_and_replace free was not allocated 的异常问题

    使用string时发现了一些坑. 我们知道stl 容器并不是线程安全的,所以在使用它们的过程中往往需要一些同步机制来保证并发场景下的同步更新. 应该踩的坑还是一个不拉的踩了进去,所以还是记录一下吧. ...

最新文章

  1. PS多形式的部分之间复制“笨办法”
  2. 【剑指offer-Java版】24二叉搜索树后序遍历序列
  3. 对集合使用Comparator
  4. python函数必背知识点_必背函数——python学习第四次总结
  5. mysql导入创建表空间_oracle创建表空间 导入数据库
  6. (转)oracle表分区详解
  7. hdu 3549 最大流(EK实现)
  8. 将公司的主要项目从eclipse迁移到android studio for mac环境(1)
  9. 面试官:CountDownLatch 与 CyclicBarrier 的使用场景?有什么区别?
  10. luogu P1375 小猫
  11. mac 回车键、空格键失灵(非物理原因)解决方法
  12. 【转载】Altera FPGA使用通用SPI Flash(代替EPCS的方法)
  13. 2019美国大学计算机本科排名,美国大学计算机排名2019最新排名
  14. 台式计算机强制关机,台式机如何强制关机
  15. linux redhat 去掉警报声音
  16. 解决ubuntu无法解析域名、无网络连接问题
  17. PeopleSoft如何配置SMTP邮件服务
  18. 红米5双清_红米5刷recovery教程_红米5第三方中文recovery下载
  19. sshpass命令的安装使用
  20. redisHyperLogLog原理解析

热门文章

  1. 微信电脑版 V3.3.0.84 多开消息防撤回绿色版
  2. perl 模块使用范例
  3. 为什么需要职场软实力
  4. [BD 41-758] The following clock pins are not connected to a valid clock source
  5. html网页鼠标样式、css精灵、iconfont、过渡动画笔记
  6. Pycharm 常用快捷键大全【快查字典版】
  7. Windows下手把手教Snort的安装与配置教程
  8. 着急上市的喜马拉雅FM,进退两难
  9. 看完这篇关于电池的高票回答 可防储能大忽悠
  10. BT656 bt601