char * 、BSTR、long、wchar_t *、LPCWSTR、string、QString、CStringA类型转换
char* 转 BSTR
char* s1 = "zhangsan";
CString s2 = CString(s1);
BSTR s3 = s2.AllocSysString();
char* 转 LPCWSTR
char* a = "a.jpg";
WCHAR b[256];
memset(b, 0, sizeof(b));
MultiByteToWideChar(CP_ACP, 0, a, strlen(a) + 1, b, sizeof(b) / sizeof(b[0]));
long 转 char*
// param[0]: long,要转换的数字
// param[1]: char *,转换后指向字符串的指针
// param[2]: 进制
ltoa(age, "age is ", 10);
char* 转 CStringA
char* ch1 = "中文测试123";
CStringA str(ch1);
CStringA 转 char*
CStringA str = L"";
char* ch2 = new char[str.GetLength()+1];
memset(ch2, 0, str.GetLength()+1);
strcpy(ch2, str.GetString());
delete ch2;
CString 转 BSTR
CString a = "abc";
BSTR b = a.AllocSysString();
wchar_t * 转 char *
wchar_t buffer[MAX_PATH];
BOOL result = SHGetSpecialFolderPath(0, buffer, CSIDL_LOCAL_APPDATA, false);
wcscat(buffer, L"\\GPR.log"); int iSize;
char* pszMultiByte; //返回接受字符串所需缓冲区的大小,已经包含字符结尾符'\0'
iSize = WideCharToMultiByte(CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL);
pszMultiByte = (char*)malloc(iSize * sizeof(char));
WideCharToMultiByte(CP_ACP, 0, buffer, -1, pszMultiByte, iSize, NULL, NULL);
string 转 BSTR
#include <string>
#include <comutil.h>
#pragma comment(lib, "comsuppw.lib") std::string a = "hello world";
_bstr_t bstr_t(a.c_str());
BSTR res_bstr = bstr_t.GetBSTR();
BSTR 转 string
#include <string>
#include <comutil.h>
#pragma comment(lib, "comsuppw.lib") BSTR s = L"hello world";
_bstr_t bstr_t(s);
std::string str(bstr_t);
QString 转 BSTR
方法一:
QString qstr;
BSTR bstr = SysAllocString((OLECHAR*)qstr.unicode());
方法二:
BSTR str = (BSTR)(LPCWSTR)qstr.data();
QString 转 char*
// 方法一
QString str;
char* ch;
QByteArray ba = str.toLatin1();
ch = ba.data(); // 方法二
std::string str = QString("zhangsan").toStdString();
const char* ch = str.c_str();
BSTR 转 QString
方法一:
QString Demo::bstrToqstring(BSTR bstr)
{
char buf[260] = { 0 };
int len = WideCharToMultiByte(CP_ACP, 0, bstr, wcslen(bstr), NULL, 0, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, bstr, wcslen(bstr), buf, len, NULL, NULL);
return QString(buf);
}
方法二:
// 获取并显示友好名称
WCHAR *aa = EloamGlobal_GetFriendlyName(1, 0);
QString s = QString::fromWCharArray(aa);
方法三:
BSTR data = EloamGlobal_GetBarcodeData(0x02);
QString str_InvocrNo = QString::fromStdWString(data);
char * 、BSTR、long、wchar_t *、LPCWSTR、string、QString、CStringA类型转换的更多相关文章
- 深入理解c++中char*与wchar_t*与string以及wstring之间的相互转换 [转]
本篇文章是对c++中的char*与wchar_t*与string以及wstring之间的相互转换进行了详细的分析介绍,需要的朋友参考下. #ifndef USE_H_ #define USE_H_ # ...
- 深入理解c++中char*与wchar_t*与string以及wstring之间的相互转换
本篇文章是对c++中的char*与wchar_t*与string以及wstring之间的相互转换进行了详细的分析介绍,需要的朋友参考下-复制代码 代码如下: #ifndef USE_H_ ...
- CString char BSTR 转换
关于字符集不一的历史原因,可以参考: UNICODE与ANSI的区别 以下是网上转载的资料.我将辅以自己的实例,说明并总结关系. 一.CString, int, string, char*之间的转换 ...
- wchar_t*转换string
场景 wchar[]转换string 实现代码 #include "stdafx.h" #include <iostream> #include <windows ...
- char[]转换成wchar_t的转换方法(GNU Libc规定wchar_t为32位)
wchar_t是C/C++的字符数据类型,是一种扩展的字符存储方式,wchar_t类型主要用在国际化程序的实现中,但它不等同于unicode编码.unicode编码的字符一般以wchar_t类型存储. ...
- int与string之间的类型转换--示例
package demo; public class IntDemo { public static void main(String[] args) { // String-->int 类型转 ...
- Date、String和Timestamp类型转换
1.String与Date类型转换: 1.获取当前系统时间: Date date1 = new Date(); //获取系统当前时间 Calendar cal = Calendar.getInst ...
- Java,mysql String与date类型转换
String 与 date类型转换 字符串转换成日期类型: SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");//小写 ...
- TCHAR和CHAR类型的互转,string 转lpcwstr
https://www.cnblogs.com/yuguangyuan/p/5955959.html 没有定义UNICODE,所以它里面的字符串就是简单用" "就行了,创建工程的时 ...
- System::String *,char*,string 等的类型转换 [转]
在VC 的编程中,经常会用到各种类型的转换,在MFC中textbox等控件得到的返回类型是System::String *,而写入的文件要求是 const char *类型的,下面介绍一些转换的方法: ...
随机推荐
- signature hdr data: BAD, no. of btyes(9088) out of range 问题排查与解决方案
在使用yum工具安装gcc的时候,报出了signature hdr data: BAD, no. of btyes(9088) out of range 的问题 这是由于centos8中rpm工具存在 ...
- 【Azure 应用服务】Python Function App重新部署后,出现 Azure Functions runtime is unreachable 错误
问题描述 Python Function App重新部署后,出现 Azure Functions runtime is unreachable 错误 问题解答 在Function App的门户页面中, ...
- 【Azure 事件中心】Event Hub Client 连接超时(OperationTimeout)测试及解说
Azure Event Hub(Azure事件中心) 是大数据流式处理平台和事件引入服务. 它可以每秒接收和处理数百万个事件.在我们的使用中,需要代码编写的是两个部分:事件生产者和事件接收者 事件生成 ...
- 【Azure 应用服务】Azure Function 不能被触发
问题描述 Azure Function 不能被Postman 触发,错误信息如下: Error: write EPROTO 4020778632:error:100000f7:SSL routines ...
- Java 小练习(2) 利用面向对象的编程方法 设计类Circle计算圆的面积
1 package com.bytezero.exer; 2 /*** 3 * 4 * @Description 5 * @author Bytezero·zhenglei! Email:420498 ...
- spingboot打造教育平台(谷粒学院课程笔记)
第一单fqb 申明,项目的框架技术架构,前端运行时node 后端框架spring 开发前准备:mysbatis官网随时看文档,IDEa 202编释器2 环境配置,idea配置一下mavem路 ...
- 适用mybatis和jpa的全数据库类型主键生成插件,分布式高并发有序id生成器
适用mybatis和jpa的全数据库类型主键生成插件,分布式高并发有序id生成器
- 通过 TCPView KPKIService.exe 删掉 (原来是单点登录的中间件)
叫 统一安全中间件,就是个第三方做的key的安全检查,谁知道是哪年装的 (原来是单点登录的中间件) 资料 https://baijiahao.baidu.com/s?id=17173842191483 ...
- centos 添加 公钥,root不用输入密码 ssh-keygen
centos 添加 公钥,root不用输入密码 ssh-keygen -t rsa -C "yourEmail" 一通回车后,生成 C:\Users\Reciter/.ssh/id ...
- be动词 系动词 连缀动词 Linking Verb
be动词 系动词 连缀动词 Linking Verb be 原型 am 第一人称单数形式 is 第三人称单数形式 are 第二人称单数和复数形式 been 过去分词 being 现在分词 was 第一 ...