如何从LPCSTR转换为LPCWSTR在c ++ [英] how to convert from LPCSTR to LPCWSTR in c++

查看:267
本文介绍了如何从LPCSTR转换为LPCWSTR在c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

附加信息
建立一个使用WinHttpOpenRequest Api的应用程序,它需要LPCWSTR作为对象名
和im使用visual studio 2008

additional info im building an application which use the WinHttpOpenRequest Api which requires LPCWSTR for the object name and im using visual studio 2008

推荐答案

最简单的方法是使用ATL:

The simplest way is to use ATL:

#include <Windows.h>
#include <atlbase.h>
#include <iostream>

int main(int argc, char *argv[]) {
    USES_CONVERSION;
    LPCSTR a = "hello";
    LPCWSTR w = A2W(a);
    std::wcout << w << std::endl;
    return 0;
}

任何由A2W分配的内存退出。

Any memory allocated by A2W (ANSI to Wide) will be freed when the function exits.

这篇关于如何从LPCSTR转换为LPCWSTR在c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆